日期和时间选择器在Oreo版本中无法正确显示

时间:2018-07-02 13:24:58

标签: android datepicker timepicker

在我的应用程序中使用日期和时间选择器时,以下奥利奥版本显示正确。但是在奥利奥版本中显示不正确。

我只引用了此链接:

  

https://www.journaldev.com/9976/android-date-time-picker-dialog

代码:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnDatePicker=(Button)findViewById(R.id.btn_date);
        btnTimePicker=(Button)findViewById(R.id.btn_time);
        txtDate=(EditText)findViewById(R.id.in_date);
        txtTime=(EditText)findViewById(R.id.in_time);

        btnDatePicker.setOnClickListener(this);
        btnTimePicker.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {

        if (v == btnDatePicker) {

            // Get Current Date
            final Calendar c = Calendar.getInstance();
            mYear = c.get(Calendar.YEAR);
            mMonth = c.get(Calendar.MONTH);
            mDay = c.get(Calendar.DAY_OF_MONTH);


            DatePickerDialog datePickerDialog = new DatePickerDialog(this,
                    new DatePickerDialog.OnDateSetListener() {

                        @Override
                        public void onDateSet(DatePicker view, int year,
                                              int monthOfYear, int dayOfMonth) {

                            txtDate.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);

                        }
                    }, mYear, mMonth, mDay);
            datePickerDialog.show();
        }
        if (v == btnTimePicker) {

            // Get Current Time
            final Calendar c = Calendar.getInstance();
            mHour = c.get(Calendar.HOUR_OF_DAY);
            mMinute = c.get(Calendar.MINUTE);

            // Launch Time Picker Dialog
            TimePickerDialog timePickerDialog = new TimePickerDialog(this,
                    new TimePickerDialog.OnTimeSetListener() {

                        @Override
                        public void onTimeSet(TimePicker view, int hourOfDay,
                                              int minute) {

                            txtTime.setText(hourOfDay + ":" + minute);
                        }
                    }, mHour, mMinute, false);
            timePickerDialog.show();
        }
    }
}

注意:请参阅该图像,该图像在oreo版本中无法正确显示,我不知道原因。请提供一些帮助。相同的代码在另一应用程序中有效,但在这里不起作用。

compileSdkVersion 27
buildToolsVersion '27.0.2'
defaultConfig {
    applicationId "fadila.new_tech.app"
    minSdkVersion 16
    targetSdkVersion 27
    versionCode 6
    versionName "1.5"
    multiDexEnabled true
}

enter image description here

enter image description here

0 个答案:

没有答案