JDJ*_*JDJ 17 android android-timepicker android-5.0-lollipop
我在Android L模拟器上测试我的应用程序,我注意到TimePickerDialog已经显着改变了:

这不符合我的应用程序的主题,我想知道在Android L上运行时是否可以获得旧的TimePickerDialog样式.
yeh*_*att 34
将android:timePickerMode ="spinner"添加到XML
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner">
</TimePicker>
Run Code Online (Sandbox Code Playgroud)
https://developer.android.com/reference/android/R.attr.html#timePickerMode
您可以选择微调器或时钟模式.此属性仅在API级别21中可用,在此之前,微调器模式是唯一可用的选项.
Dan*_*n J 15
如果你想让AM/PM成为一个选择器而不是一个按钮,那么我建议你使用单个参数构造函数ContextThemeWrapper:
new TimePicker(new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Light_Dialog_NoActionBar));
Run Code Online (Sandbox Code Playgroud)

如果您将主题传递给多参数构造函数,那么您最终会得到一个相当丑陋的AM/PM按钮,并且小时和分钟列之间将缺少冒号.
new TimePicker(getActivity(), null, TimePickerDialog.THEME_HOLO_LIGHT);
Run Code Online (Sandbox Code Playgroud)

Lor*_*nMK 11
您可以使用带参数的TimePickerDialog构造theme函数来指定主题.
TimePickerDialog(Context context,
int theme,
TimePickerDialog.OnTimeSetListener callBack,
int hourOfDay,
int minute,
boolean is24HourView)
Run Code Online (Sandbox Code Playgroud)
正如 LordRaydenMK 所说,使用TimePickerDialog带theme参数的构造函数并提供这个主题:android.R.style.CustomDatePickerDialog
在你Styles.xml定义这个:
<style name="CustomDatePickerDialog"
parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:dialogTheme">@style/MyDialogTheme</item>
<item name="android:timePickerStyle">@style/MyDatePicker</item>
</style>
<style name="MyDialogTheme"
parent="Theme.AppCompat.Light.Dialog">
<item name="android:timePickerStyle">@style/MyDatePicker</item>
</style>
<style name="MyDatePicker"
parent="@android:style/Widget.Material.Light.TimePicker">
<item name="android:timePickerMode">spinner</item>
</style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29886 次 |
| 最近记录: |