样式datepicker

时间:2015-06-16 14:06:47

标签: android datepicker

我想显示一个带有日期选择器的alertdialog。 datepicker应该是具有3个号码选择器的旧日期选择器样式。但是我有一些麻烦造型。

这是我的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();
    }
}

这是我的布局

当我使用日历视图datepicker时,我的应用程序主题的accentColor被应用。

<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

但是当我使用微调模式时:

<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"/>

忽略了我的强调色:

enter image description here

我该如何解决这个问题?

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>

0 个答案:

没有答案