Skip to content Skip to sidebar Skip to footer

Android Timepickerdialog Material Design Color

I am using a time picker dialog in my app. I am also using appcompat to give my app material design theme. The dialog however stays with the default teal accent color (my accent

Solution 1:

This can be easily achieved from xml (5.0+ only)

v21/themes.xml

<resourcesxmlns:android="http://schemas.android.com/apk/res/android"><stylename="Theme"parent="MyTheme.Base"><itemname="android:dialogTheme">@style/Theme.Dialog</item><!-- TimePicker dialog --><itemname="android:alertDialogTheme">@style/Theme.Dialog</item><!-- Alert dialog --></style><stylename="Theme.Dialog"parent="android:Theme.Material.Light.Dialog"><itemname="android:colorAccent">@color/...</item><itemname="android:colorPrimary">@color/...</item><itemname="android:colorPrimaryDark">@color/...</item></style></resources>

Edit Please note that as of Android Support Library 22.1.0 there is a new AppCompatDialog available! http://android-developers.blogspot.de/2015/04/android-support-library-221.html

Solution 2:

You can override the colors using:

TimePickerDialogtimePickerDialog=newTimePickerDialog(this, 
          R.style.themeOnverlay_timePicker,   //theme overlay
          timeSetListener,
          hours,minutes,true);

with:

<stylename="themeOnverlay_timePicker"parent="@style/ThemeOverlay.MaterialComponents.Dialog"><itemname="colorControlActivated">@color/....</item><itemname="colorAccent">@color/....</item><itemname="android:textColorPrimary">@color/.....</item><itemname="android:textColorSecondary">@color/.....</item></style>

If you are using an AppCompat theme use ThemeOverlay.AppCompat.Dialog as parent.

enter image description here

enter image description here

Post a Comment for "Android Timepickerdialog Material Design Color"