Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change timepicker background color in dialog

I've got a time picker in my custom dialog. This is the result :

enter image description here

This is my code:

<style name="DialogStyler2" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:background">#FFFFFF</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:windowNoTitle">true</item>
</style>

final Dialog dialog = new Dialog(SabadKharid_s1.this, R.style.DialogStyler2);
                    dialog.setContentView(R.layout.dialogtime);

                    timePicker = (TimePicker) dialog.findViewById(R.id.timePicker);
                    timePicker.setIs24HourView(true);

                    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                    lp.copyFrom(dialog.getWindow().getAttributes());
                    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
                    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
                    dialog.show();
                    dialog.getWindow().setAttributes(lp);

As you can see, the hour and minute textView in title the are white. How can I change their background color?

like image 662
j jones Avatar asked Mar 09 '23 08:03

j jones


1 Answers

This happens if you change the color of 'background' rather than 'windowBackground'. This worked for me:

styles.xml

<style name="DialogTheme" parent="Theme.AppCompat.Dialog">
    <item name="android:windowBackground">#333</item>
    <item name="colorAccent">#2BF</item>
</style>

MainActivity.java

Calendar cal = Calendar.getInstance();
TimePickerDialog tpd = new TimePickerDialog(
        this,
        R.style.DialogTheme,
        this, // must implement TimePickerDialog.OnTimeSetListener
        cal.get(Calendar.HOUR_OF_DAY),
        cal.get(Calendar.MINUTE),
        false);

tpd.show();
like image 160
tguen Avatar answered Mar 31 '23 06:03

tguen