Change the DatePicker Header Text Color

I have a date picker showing the title on Lollipop, it looks like this Datepicker

I want to either change the color of the big date in the title from black to white, or delete the title as a whole, I don't care. I tried to change textColorPrimary, textColorand titleTextColor, but it has no effect.

+4
source share
3 answers

Well, I don't know what the parent theme you use for the Date Picker theme is. Say you have a custom theme for your date picker, as shown below,

 <style name="yourCustomStyle" parent="Theme.AppCompat.Light">

Ctrl + Theme.AppCompat.Light, ;), , , , , , .

, , ,

android:textColorPrimaryInverse

.

   <style name="yourCustomStyle" parent="Theme.AppCompat.Light">
        <item name="colorAccent">@color/blue</item>
        <item name="android:textColorPrimaryInverse">@color/yellow</item>
        .. other
    </style>

( ), !

new DatePickerDialog(MainActivity.this, R.style.yourCustomStyle, new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

    }
}, 2015, 02, 26).show();

enter image description here enter image description here

: android: textColorPrimaryInverse Theme.AppCompat.Dialog

+4

, CustomDatePickerDialogTheme datePicker DialogFragment:

<style name="CustomDatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:datePickerStyle">@style/CustomDatePickerStyle</item>
</style>

<style name="CustomDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
    <item name="android:headerMonthTextAppearance">@style/HeaderTextStyle</item>
</style>

<style name="HeaderTextStyle" parent="@android:style/TextAppearance.Medium">
    <item name="android:textColor">@color/colorAccent</item>
</style>
+2

, :

styles.xml :

<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
       <item name="colorAccent">@color/white</item>
</style>

And add below lines to your code:

new DatePickerDialog(MainActivity.this, R.style.DialogTheme, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    //DO SOMETHING
  }
}, 2015, 02, 26).show();
0
source

Source: https://habr.com/ru/post/1670414/


All Articles