简体   繁体   English

Android DatePickerDialog 不适用于 Android 5

[英]Android DatePickerDialog is not working on Android 5

I'm working on an app, on registration form, the user needs to enter his birthday.我正在开发一个应用程序,在注册表单上,用户需要输入他的生日。 I used a DatePickerDialog.我使用了一个 DatePickerDialog。 The app works fine on my phone and on emulator but when i tested it on an old phone (android 5) the app stop functionning when i want to select the date.该应用程序在我的手机和模拟器上运行良好,但是当我在旧手机(android 5)上测试它时,当我想选择日期时,该应用程序停止运行。

This is my XML code这是我的 XML 代码

<com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Date"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        app:boxStrokeColor="@color/colorPrimary"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusableInTouchMode="false"
            android:onClick="BirthDatePicker"
            />
    </com.google.android.material.textfield.TextInputLayout>

This is my java code这是我的java代码

public void BirthDatePicker(View v) throws ParseException {
  final DatePickerDialog[] picker = new DatePickerDialog[1];
    final TextInputEditText eText;
    eText= findViewById(R.id.editText1);
    //eText.setInputType(InputType.TYPE_NULL);
    final Calendar cldr = Calendar.getInstance();
    int day = cldr.get(Calendar.DAY_OF_MONTH);
    int month = cldr.get(Calendar.MONTH);
    int year = cldr.get(Calendar.YEAR);
    // date picker dialog  DatePickerDialog.OnDateSetListener listener
    picker[0] = new DatePickerDialog(RegisterActivity.this, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                eText.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);
                setDate( dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);
                }
            }, year, month, day);

    picker[0].show();
}

setter :二传手:

 public void setDate(String date) {
        mDate = date;
    }

I put my comment in answer field because of this restriction: 'You must have 50 reputation to comment'.由于此限制,我将我的评论放在回答字段中:“您必须拥有 50 个声誉才能发表评论”。

Paste the logcat details for the actual device.粘贴实际设备的 logcat 详细信息。

I think it has something to do with the 'style' issue.我认为这与“风格”问题有关。

Do check out Date picker dialog issue in android 5 lolipop请检查android 5 棒棒糖中的日期选择器对话框问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM