Changing TimePickerDialog Styles

烂漫一生 提交于 2019-12-08 17:54:25

Try this instead

    <style name="MyAppThemeFour" parent="Theme.AppCompat.Light">
    <item name="android:timePickerDialogTheme">@style/MyTimePickerDialogStyle</item>
</style>
<style name="MyTimePickerDialogStyle" parent="@style/ThemeOverlay.AppCompat.Dialog.Alert">
<item name="showTitle">false</item>
<item name="colorControlActivated">#ffd600</item>
<item name="colorAccent">#b71c1c</item>
<item name="android:textColorPrimary">#43a047</item>
<item name="android:textColorSecondary">#f44336</item>
</style> 

    <style name="MyTimePickerWidgetStyle" parent="@android:style/Widget.Material.TimePicker">
    <item name="android:headerBackground">#ffe082</item>
    <item name="android:numbersTextColor">#b71c1c</item>
    <item name="android:numbersInnerTextColor">#f44336</item>
    <item name="android:numbersSelectorColor">#33691e</item>
    <item name="android:numbersBackgroundColor">#ef9a9a</item>
    <item name="android:amPmTextColor">#9c27b0</item>
</style>

Apply it to the timepicker like :

<TimePicker
android:id="@+id/timePicker"
android:theme="@style/MyTimePickerWidgetStyle"
style="@style/MyTimePickerWidgetStyle"
. . . />

You can use the TimePickerDialog constructor with theme parameter to specify the theme.

TimePickerDialog(Context context, 
                 int theme, 
                 TimePickerDialog.OnTimeSetListener callBack, 
                 int hourOfDay, 
                 int minute, 
                 boolean is24HourView)

OR

Add android:timePickerMode="spinner" to the XML

     <TimePicker
        android:id="@+id/timePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:timePickerMode="spinner">
    </TimePicker>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!