Reputation: 31
Update:
I updated the styling so I can now see the buttons and set their color. However, the colon between the hour and minute disappeared now. This is the style that worked for me:
<style name="AppTheme.TimePickerDialog" parent="android:Theme.Material.Light.Dialog">
<item name="android:colorControlNormal">@color/blue</item>
<item name="colorAccent">@color/black</item>
<item name="colorPrimary">@color/green</item>
<item name="android:buttonBarButtonStyle">@style/Widget.AppCompat.Button.Colored</item>
<item name="android:timePickerStyle">@style/AppTheme.TimePicker</item>
</style>
<style name="AppTheme.TimePicker">
<item name="android:timePickerMode">spinner</item>
</style>
The key change was adding the buttonBarButtonStyle as colored. This makes the buttons green and the bars of the spinner blue. I tried a couple of different properties for getting the colon to show but it hasn't worked so far.
Original Post:
I am using a TimePicker in a TimePickerDialog and struggling to change the color of the "OK" and "Cancel" buttons in my dialog. Currently the button text is white on a white background so they aren't visible.
I've tried setting many different color properties and none of them are working.
This is my current xml:
<style name="AppTheme.TimePickerDialog" parent="android:Theme.Material.Light.Dialog">
<item name="android:timePickerStyle">@style/AppTheme.TimePicker</item>
<item name="buttonBarPositiveButtonStyle">@style/AppTheme.TimePickerButtons</item>
<item name="buttonBarNegativeButtonStyle">@style/AppTheme.TimePickerButtons</item>
</style>
<style name="AppTheme.TimePicker" parent="android:Widget.Material.TimePicker">
<item name="android:timePickerMode">spinner</item>
<item name="buttonBarPositiveButtonStyle">@style/AppTheme.TimePickerButtons</item>
<item name="buttonBarNegativeButtonStyle">@style/AppTheme.TimePickerButtons</item>
</style>
<style name="AppTheme.TimePickerButtons" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">@color/white</item>
<item name="backgroundTint">@color/red</item>
</style>
I've also tried setting:
<item name="android:colorButtonNormal">@color/black</item>
<item name="android:colorControlNormal">@color/black</item>
<item name="android:colorAccent">@color/black</item>
on the TimePickerDialog but none of them affected button colors.
I have alert dialogs and DatePickerDialogs in my application that have no problems with the styling, so I'm not sure what is different in my TimePickerDialog implementation. If I don't add any time picker styling then the dialog has the right colors, but I need the styling to make it a spinner style picker instead of a clock.
Upvotes: 2
Views: 202