Lollipop 下的 TimePicker 时钟模式 [英] TimePicker Clock mode below Lollipop
问题描述
我试图让我的 TimePicker
显示为时钟.我使用 timepickermode="clock"
但我收到一个 lint 警告,说它与 api 级别 21 及更高版本兼容.
I am trying to make my TimePicker
appear as a clock. I use timepickermode="clock"
but I get a lint warning that says that it's compatible with api level 21 and above.
我在 Todoist 应用程序中看到此功能在我的 kitkat 上运行.我还应该如何实现这一点?
I've seen this feature ran on my kitkat in Todoist app. How else do I implement this?
推荐答案
文档:
timePickerMode
定义小部件的外观.在 L 版本之前,唯一的选择是微调器.从 L 开始,使用 Material 主题选中,默认布局为clock,但可以使用该属性强制使用微调器.
timePickerMode
Defines the look of the widget. Prior to the L release, the only choice was spinner. As of L, with the Material theme selected, the default layout is clock, but this attribute can be used to force spinner to be used instead.
Google 本身提供了替代方案.它是一个与 API 级别 14 及更高级别兼容的外部日期选择器项目.您可以在此处找到该项目:
There is an alternative offered by Google itself. It is an external datepicker project that is compatible with API level 14 and higher. You can find the project here:
https://android.googlesource.com/platform/frameworks/opt/datetimepicker/
克隆存储库后,将其添加到现有项目中,然后您可以像这样使用 TimePicker
:
Once you clone the repo, add it to your existing project, then you can use the TimePicker
like this:
TimePickerDialog timePickerDialog = new TimePickerDialog();
timePickerDialog.setOnTimeSetListener(new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
}
});
timePickerDialog.show(getFragmentManager(), fragmentTag);
小心导入 com.android.datetimepicker.time.TimePickerDialog
而不是标准的 android.app.TimePickerDialog
.
Be careful to import the com.android.datetimepicker.time.TimePickerDialog
not the standard android.app.TimePickerDialog
.
这篇关于Lollipop 下的 TimePicker 时钟模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!