Set theme for a Fragment

Setting Theme in manifest is usually used for Activity.

If you want to set Theme for Fragment, add next code in the onGetLayoutInflater() of the Fragment:

override fun onGetLayoutInflater(savedInstanceState: Bundle?): LayoutInflater {
    val inflater = super.onGetLayoutInflater(savedInstanceState)
    val contextThemeWrapper: Context = ContextThemeWrapper(requireContext(), R.style.yourCustomTheme)
    return inflater.cloneInContext(contextThemeWrapper)
}

Leave a Comment