Datepicker style

I want to show alertdialog with datepicker. Datepicker should be old style datepicker with 3 numberpickers. But I am having trouble with his style.

This is my DialogFragment:

public class DatePickerFragment extends DialogFragment {

    public static final String EXTRA_DATE = "EXTRA_DATE";

    private DatePicker mDatePicker;

    public static DatePickerFragment newInstance(Date date) {
        DatePickerFragment datePickerFragment = new DatePickerFragment();
        Bundle args = new Bundle();
        args.putSerializable(EXTRA_DATE, date);
        datePickerFragment.setArguments(args);
        return datePickerFragment;
    }

    public DatePickerFragment() {
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        View view = getActivity().getLayoutInflater().inflate(R.layout.datepicker, null);
        mDatePicker = (DatePicker) view.findViewById(R.id.date_picker);

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                // TODO
            }
        })
        .setNegativeButton(android.R.string.cancel, null)
        .setView(view)
        .create();

        return builder.create();
    }
}

      

This is my layout

When I use the datepicker template for a calendar, the accent color of my application theme is applied.

<DatePicker xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:calendarViewShown="true"
   android:id="@+id/date_picker"/>

      

enter image description here

But when I use spinner mode:

<DatePicker xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:calendarViewShown="false"
   android:datePickerMode="spinner"
   android:id="@+id/date_picker"/>

      

my accent color is being ignored:

enter image description here

How can I fix this?

styles.xml:

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/myPrimaryColor</item>
    <item name="colorPrimaryDark">@color/myPrimaryDarkColor</item>
    <item name="colorAccent">@color/myAccentColor</item>

    <item name="android:colorPressedHighlight">@color/ripple_gray</item>
    <item name="android:colorLongPressedHighlight">@color/ripple_gray</item>

    <item name="android:windowBackground">@color/myWindowBackground</item>
    <item name="alertDialogTheme">@style/AppTheme.DialogTheme</item>

</style>

 <style name="AppTheme.DialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorPrimary">@color/myPrimaryColor</item>
    <item name="colorPrimaryDark">@color/myPrimaryColor</item>
    <item name="colorAccent">@color/myPrimaryColor</item>
</style>

      

+3


source to share





All Articles