Изменить тему от фрагмента - PullRequest
0 голосов
/ 13 февраля 2020

У меня проблема с тем, что я не могу изменить тему стиля. Я хочу убедиться, что каждый раз при переходе к разным фрагментам тема приложения будет меняться. Надежда может помочь мне решить эту проблему. Заранее спасибо.

enter image description here

class MainKonsesiFragment : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {


        //create ContextThemeWrapper from the original Activity Context with the custom theme
        val context = ContextThemeWrapper(activity, R.style.AppKonsesiTheme)
        //clone the inflater using the ContextThemeWrapper
        val localInflater = inflater.cloneInContext(context)

        val binding:FragmentMainKonsesiBinding = DataBindingUtil.inflate(localInflater,R.layout.fragment_main_konsesi,container,false)

        binding.cardInputPemantauan.setOnClickListener(
            Navigation.createNavigateOnClickListener(R.id.action_mainKonsesiFragment_to_inputPemantauanFragment)
        )
        binding.cardListKonsesi.setOnClickListener(
            Navigation.createNavigateOnClickListener(R.id.action_mainKonsesiFragment_to_listKonsesiFragment)
        )
        return binding.root
    }
}

1 Ответ

0 голосов
/ 13 февраля 2020

Можете ли вы попробовать

 getActivity.getTheme().applyStyle(R.style.AppKonsesiTheme, true);

и, возможно, даже позвонить

getActivity().recreate();

, если потребуется. Возможно, вы захотите сменить тему перед созданием фрагмента

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...