Ace*_*ela 7 android android-timepicker material-design
我在我的应用程序中使用时间选择器对话框.我也使用appcompat来提供我的应用程序材料设计主题.然而,对话框保持默认的蓝绿色强调色(我的重点是淡蓝色).
所以在我的代码中,我尝试将对话框主题设置为我自己的,并且它接受它使其全屏
mTimePicker = new TimePickerDialog(ctx, R.style.AppTheme new TimePickerDialog.OnTimeSetListener() {->}, hour, minute, DateFormat.is24HourFormat(context));
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何设置TimePickerDialog以正确显示我的颜色而不是默认颜色?
Tai*_*aig 16
这可以通过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>
Run Code Online (Sandbox Code Playgroud)
编辑
请注意,从Android支持库22.1.0开始,有一个新的AppCompatDialog可用!http://android-developers.blogspot.de/2015/04/android-support-library-221.html
您可以使用以下方法覆盖颜色:
TimePickerDialog timePickerDialog = new TimePickerDialog(this,
R.style.themeOnverlay_timePicker, //theme overlay
timeSetListener,
hours,minutes,true);
Run Code Online (Sandbox Code Playgroud)
和:
<style name="themeOnverlay_timePicker" parent="@style/ThemeOverlay.MaterialComponents.Dialog">
<item name="colorControlActivated">@color/....</item>
<item name="colorAccent">@color/....</item>
<item name="android:textColorPrimary">@color/.....</item>
<item name="android:textColorSecondary">@color/.....</item>
</style>
Run Code Online (Sandbox Code Playgroud)
如果您使用 AppCompat 主题,请用作ThemeOverlay.AppCompat.Dialog父主题。