TimePickerDialog CANCEL and OK button not showing

For me the color of ok and cancel button were white , it was because my colorOnPrimary was set to white .

<item name="colorOnPrimary">@color/white</item>

And Timepicker used it , to fix that you can change that to black or any color you want.

<item name="colorOnPrimary">@color/black</item>

Or just add a new colorOnPrimary inside a custom theme and use it for timepicker.

<style name="MyTimePickerDialogTheme" parent="@style/Theme.AppCompat.Light.Dialog">
 <item name="colorOnPrimary">@color/black</item>
</style>

I fixed the issue, I think for some reasons the font color for the buttons were showing as white sometimes, have no idea why.

To fix the issue, I added a dialog theme to the TimePickerDialog to set the button text color.

Here is the xml code I added to styles.xml

<style name="MyTimePickerDialogTheme" parent="@style/Theme.AppCompat.Light.Dialog">
     <item name="android:textColor">@color/colorAccent</item>
     <item name="colorAccent">@color/colorAccent</item>
</style>

And here is the code I changed.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Use the current time as the default values for the picker
    final Calendar c = Calendar.getInstance();
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);

    Bundle b = getArguments();

    if (b != null) {
        startEndTime = b.getString("startEndTime");
    }


    // Create a new instance of TimePickerDialog and return it
    return new TimePickerDialog(getActivity(), R.style.MyTimePickerDialogTheme, this, hour, minute, DateFormat.is24HourFormat(getActivity()));
}

Tags:

Android