android - Android DatePickerDialog 不适用于 Android 5
问题描述
我正在开发一个应用程序,在注册表单上,用户需要输入他的生日。我使用了 DatePickerDialog。该应用程序在我的手机和模拟器上运行良好,但是当我在旧手机(android 5)上测试它时,当我想选择日期时,应用程序停止运行。
这是我的 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>
这是我的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();
}
二传手:
public void setDate(String date) {
mDate = date;
}
解决方案
由于此限制,我将我的评论放在答案字段中:“您必须有 50 名声望才能发表评论”。
粘贴实际设备的 logcat 详细信息。
我认为这与“风格”问题有关。
推荐阅读
- python - 如何从字节转换为整数?
- android - 如何播放列出的音频并执行 listview.OnItemClickListener?
- html - 如何在离子视图中向 div 标签添加点击/点击功能?
- c# - 无法添加 System.Web.Extensions 程序集作为参考
- php - 根据他们在forloop php中的组名显示数据
- android - sha1 不能与 Auth Phone 一起使用
- ruby-on-rails - 如何对存储在 Rails 5.1 和 PG 的 JSONb 字段中的多个值求和
- unix - Fortran 错误:(1) 处的续行错误
- c - 在 AVL 树 C 中插入和删除
- javascript - 我想在数组中打印数据