Date picker dialog issue in android 5 lolipop

﹥>﹥吖頭↗ 提交于 2021-02-10 20:43:36

问题


I can't show the another date in android 5 lollipop.

DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker datePicker, int year, int month, int dayOfMonth) {

                        }
                    };

DatePickerDialog datePickerDialog = new DatePickerDialog(activity, R.style.DatePickerDialogStyle, onDateSetListener, 2019, 9, 19);

datePickerDialog.show();

I am use below datepicker style

 <style name="DatePickerDialogStyle">
        <item name="showTitle">false</item>
        <item name="colorControlActivated">@color/colorAccent</item>
        <item name="android:headerBackground">@color/colorAccent</item>
  </style>

回答1:


  • I think it's a Style issue.

Just check it

In my code, I have added custom style which name is "DatePickerDialogStyle"

In style.xml file add this style:-

<style name="DatePickerDialogStyle">
    <item name="showTitle">false</item>
    <item name="colorControlActivated">@color/colorAccent</item>
    <item name="android:headerBackground">@color/colorAccent</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:textColorSecondary">@color/black</item>
</style>

Example :-

DatePickerDialog datePickerDialog = new DatePickerDialog(activityName.this, R.style.DatePickerDialogStyle, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {

                }
            }, year, month, day);
            datePickerDialog.show();

I hope It will work.




回答2:


You need have to just remove theme in Object of DatePickerDialog

your object of DatePickerDialog initialisation will be like this

DatePickerDialog(getViewActivity(), onDateSetListener,  Calendar.getInstance().get(Calendar.YEAR), Calendar.getInstance().get(Calendar.MONTH), Calendar.getInstance().get(Calendar.DAY_OF_MONTH))

Let me know if it working or not i haven't check this in Lollipop device



来源:https://stackoverflow.com/questions/58022135/date-picker-dialog-issue-in-android-5-lolipop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!