Android TimePickerDialog material design color

拈花ヽ惹草 提交于 2019-11-29 09:31:09

问题


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 is a light blue).

so in my code I tried setting the dialog theme to my own and it works accept it makes it fullscreen

mTimePicker = new TimePickerDialog(ctx, R.style.AppTheme new TimePickerDialog.OnTimeSetListener() {->}, hour, minute, DateFormat.is24HourFormat(context));

does anyone know how to set the TimePickerDialog to show correctly with my colors instead of the default ones?


回答1:


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

v21/themes.xml

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="Theme"
           parent="MyTheme.Base">

        <item name="android:dialogTheme">@style/Theme.Dialog</item> <!-- TimePicker dialog -->
        <item name="android:alertDialogTheme">@style/Theme.Dialog</item> <!-- Alert dialog -->

    </style>

    <style name="Theme.Dialog"
           parent="android:Theme.Material.Light.Dialog">

        <item name="android:colorAccent">@color/...</item>
        <item name="android:colorPrimary">@color/...</item>
        <item name="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



来源:https://stackoverflow.com/questions/27873131/android-timepickerdialog-material-design-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!