我在我的应用程序中使用时间选择器对话框。我也在使用 appcompat 给我的应用程序设计主题。然而,该对话框保持默认的蓝绿色强调色(我的强调色是浅蓝色)。
所以在我的代码中,我尝试将对话框主题设置为我自己的主题,并且可以接受它使其全屏显示
mTimePicker = new TimePickerDialog(ctx, R.style.AppTheme new TimePickerDialog.OnTimeSetListener() {->}, hour, minute, DateFormat.is24HourFormat(context));
有谁知道如何设置 TimePickerDialog 以使用我的颜色而不是默认颜色正确显示?
最佳答案
这可以从 xml 轻松实现(仅限 5.0+)
v21/themes.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme"
parent="MyTheme.Base">
<item name="android:dialogTheme">@style/Theme.Dialog</item> <!-- TimePicker dialog -->
<item name="android:alertDialogTheme">@style/Theme.Dialog</item> <!-- Alert dialog -->
</style>
<style name="Theme.Dialog"
parent="android:Theme.Material.Light.Dialog">
<item name="android:colorAccent">@color/...</item>
<item name="android:colorPrimary">@color/...</item>
<item name="android:colorPrimaryDark">@color/...</item>
</style>
</resources>
编辑
请注意,从 Android 支持库 22.1.0 开始,有一个新的 AppCompatDialog
可用! http://android-developers.blogspot.de/2015/04/android-support-library-221.html
关于Android TimePickerDialog Material 设计颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27873131/