Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatePickerDialog has blacked out buttons in androidx.fragment.app.DialogFragment

This simple class:

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)
    }
}

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.

Dialog

like image 639
Nominalista Avatar asked Jan 03 '23 08:01

Nominalista


1 Answers

The problem comes from Theme.MaterialComponents.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.

Your solution would be to just use Theme.Design.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>

You could replace it with another *ViewInflater and there is not much choice but:

<item name="viewInflaterClass">androidx.appcompat.app.AppCompatViewInflater</item>

It works, but I would not rely on it too much, as using Inflater from another package might cause weird issues.

like image 134
michalbrz Avatar answered Jan 05 '23 17:01

michalbrz