我正在尝试为 fragment 设置主题。
在 list 中设置主题不起作用:
android:theme="@android:style/Theme.Holo.Light"
通过查看以前的博客,似乎我必须使用 ContextThemeWrapper。任何人都可以向我推荐一个编码示例吗?我什么也找不到。
最佳答案
在 manifest 中设置 Theme 通常用于 Activity。
如果要为 Fragment 设置 Theme,在 Fragment 的 onGetLayoutInflater() 中添加下一段代码:
override fun onGetLayoutInflater(savedInstanceState: Bundle?): LayoutInflater {
val inflater = super.onGetLayoutInflater(savedInstanceState)
val contextThemeWrapper: Context = ContextThemeWrapper(requireContext(), R.style.yourCustomTheme)
return inflater.cloneInContext(contextThemeWrapper)
}
关于android - 为 fragment 设置主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9469174/