DatePickerDialog无法按预期工作 [英] DatePickerDialog not working as expected

查看:88
本文介绍了DatePickerDialog无法按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 EditView ,我试图在其中绑定 DatePickerDialog 。它与 api 19 一起使用时效果很好。但是在 api版本25 棉花糖上测试时,日历变成白色,并且在选择某个日期时, EditView 也没有填充,即我无法设置日期在棉花糖中。

I have an EditView in which I am trying to bind DatePickerDialog. Its working well with the api 19. but when tested on api version 25 Marshmallow the calendar becomes white and when selected some date the EditView is not populated as well i.e I am unable to set date in Marshmallow.

代码:

warrantyExpEt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new DatePickerDialog(getContext(), date, myCalendar
                        .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
                        myCalendar.get(Calendar.DAY_OF_MONTH)).show();
            }
        });


    final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear,
                                  int dayOfMonth) {
                // TODO Auto-generated method stub
                myCalendar.set(Calendar.YEAR, year);
                myCalendar.set(Calendar.MONTH, monthOfYear);
                myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                updateLabel();
            }

        };
        private void updateLabel() {

            String myFormat = "yyyy-MM-dd";
            SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);

            warrantyExpEt.setText(sdf.format(myCalendar.getTime()));
        }


推荐答案

从您的样式中删除此内容:

Remove this from your style:

<item name="android:textColorPrimary">@color/white</item>

这篇关于DatePickerDialog无法按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆