问题描述
我目前正在构建一个针对API 23的应用,该API的最低要求为16.我遇到了一个问题,即在AlertDialog中显示TimePicker.在Nexus 5 API< = 22上启动应用程序时,在纵向模式和横向模式下,显示效果都很好.但是,在Nexus 5 API 23上启动应用程序时,横向模式无法正确显示TimePicker小部件,而仅显示其背景颜色.
I'm currently building an app targeting API 23, with a minimum API 16.I'm facing an issue where a TimePicker is displayed within an AlertDialog. The display looks fine on Portrait mode and on Landscape mode when launching the app on Nexus 5 API <=22. However, when launching the app on a Nexus 5 API 23, the landscape mode does not correctly display the TimePicker widget, it displays only its background colors.
-
在Nexus 5 API 23(纵向)上:肖像模式下的时间选择器(API 23)
On Nexus 5 API 23 (Portrait):TimePicker on Portrait mode (API 23)
在Nexus 5 API 23(横向)上:横向模式下的时间选择器(API 23)
On Nexus 5 API 23 (Landscape):TimePicker on Landscape mode (API 23)
推荐答案
您必须从时间选择器对话框中删除设置标题,然后才能在Nexus 5中看到时间选择器对话框.此问题发布在Google论坛上,请参见以下链接:
You have to remove set title from time picker dialogue after that you will see time picker dialogue in Nexus 5. This issue is posted on google forum see below link :
https://code.google.com/p/android/issues/detail?id = 201766
TimePickerDialog mTimePicker;
String[] time = txtTimeWriteOut.getText().toString().trim().split(":");
int hour = Integer.parseInt(time[0]);
int minute = Integer.parseInt(time[1]);
mTimePicker = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
txtTimeWriteOut.setText(TimeUtils.getDoubleDigits(selectedHour) + ":" + TimeUtils.getDoubleDigits(selectedMinute));
passTimeOut = currentDate + TimeUtils.getDoubleDigits(selectedHour) + TimeUtils.getDoubleDigits(selectedMinute) + "00";
}
}, hour, minute, true);
// mTimePicker.setTitle("Select Time");
mTimePicker.show();
这篇关于Android TimePicker在横向模式下无法正常显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!