DatePickerDialog已涂黑androidx.fragment.app.DialogFragment中的按钮 [英] DatePickerDialog has blacked out buttons in androidx.fragment.app.DialogFragment
问题描述
这个简单的类:
class DateSelectionDialogFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val calendar = Calendar.getInstance()
val year = calendar.get(Calendar.YEAR)
val month = calendar.get(Calendar.MONTH)
val dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH)
return DatePickerDialog(requireContext(), this, year, month, dayOfMonth)
}
}
导致按钮行为异常.重要的是我没有为对话框指定任何样式. DialogFragment
来自androidx.fragment.app
软件包.
results in strangely behaving buttons. What's important I didn't specify any style for the dialog. The DialogFragment
is from androidx.fragment.app
package.
推荐答案
问题来自Theme.MaterialComponents.Light.NoActionBar
.
这是很新的(和alpha版本),它应该替代Theme.Design.Light.NoActionBar
,但是正如我们看到的那样,它还不够好.
It's pretty new (and alpha) and it should replace Theme.Design.Light.NoActionBar
but as we can see, it's not good enough yet.
您的解决方案是只使用Theme.Design.Light.NoActionBar
.
Your solution would be to just use Theme.Design.Light.NoActionBar
.
但是如果您真的要使用Theme.MaterialComponents.Light.NoActionBar
...问题是由主题中的此设置引起的:
But if you really want to use Theme.MaterialComponents.Light.NoActionBar
... The problem is caused by this setting in theme:
<item name="viewInflaterClass">com.google.android.material.theme.MaterialComponentsViewInflater</item>
您可以将其替换为另一个*ViewInflater
,但没有太多选择,但是:
You could replace it with another *ViewInflater
and there is not much choice but:
<item name="viewInflaterClass">androidx.appcompat.app.AppCompatViewInflater</item>
它可以工作,但是我不会过分依赖,因为从其他软件包中使用Inflater可能会引起奇怪的问题.
It works, but I would not rely on it too much, as using Inflater from another package might cause weird issues.
这篇关于DatePickerDialog已涂黑androidx.fragment.app.DialogFragment中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!