War*_*zit 100 android styles dialog background-color
是否可以更改android 5.0的datepicker(以及timepicker)配色方案?
我尝试设置强调色,但这不起作用(有和没有android:):
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/purple</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">@color/purple_tint</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">@color/purple_tint</item>
Run Code Online (Sandbox Code Playgroud)
来自原文:

对于这样的事情:

Vik*_*ram 298
Neil的建议导致全屏的原因DatePicker是父主题的选择:
<!-- Theme.AppCompat.Light is not a dialog theme -->
<style name="DialogTheme" parent="**Theme.AppCompat.Light**">
<item name="colorAccent">@color/blue_500</item>
</style>
Run Code Online (Sandbox Code Playgroud)
此外,如果你走这条路线,你必须在创建时指定主题DatePickerDialog:
// R.style.DialogTheme
new DatePickerDialog(MainActivity.this, R.style.DialogTheme, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
//DO SOMETHING
}
}, 2015, 02, 26).show();
Run Code Online (Sandbox Code Playgroud)
在我看来,这并不好.应该尝试将样式保留在java和styles.xml/themes.xml中.
我确实同意Neil的建议,稍微改变一下(改变父主题Theme.Material.Light.Dialog),会得到你想要的结果.但是,这是另一种方式:
在第一次检查时,我们遇到datePickerStyle了以下内容:(headerBackground您要改变的内容)dayOfWeekBackground,以及其他一些文本颜色和文本样式.
在您的应用主题中覆盖此属性将不起作用.DatePickerDialog使用可由属性分配的单独主题datePickerDialogTheme.因此,为了使我们的更改生效,我们必须在重写datePickerStyle内部覆盖datePickerDialogTheme.
开始了:
覆盖datePickerDialogTheme应用内部基本主题:
<style name="AppBaseTheme" parent="android:Theme.Material.Light">
....
<item name="android:datePickerDialogTheme">@style/MyDatePickerDialogTheme</item>
</style>
Run Code Online (Sandbox Code Playgroud)
定义MyDatePickerDialogTheme.父主题的选择将取决于您的应用程序的基本主题:它可以是Theme.Material.Dialog或Theme.Material.Light.Dialog:
<style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog">
<item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我们已经超越datePickerStyle了风格MyDatePickerStyle.父母的选择将再次取决于您的应用程序的基本主题是什么:Widget.Material.DatePicker或者Widget.Material.Light.DatePicker.根据您的要求定义它:
<style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
<item name="android:headerBackground">@color/chosen_header_bg_color</item>
</style>
Run Code Online (Sandbox Code Playgroud)
目前,我们仅覆盖headerBackground默认设置为?attr/colorAccent(这也是Neil建议在更改背景时的原因).但是有很多可能的定制:
dayOfWeekBackground
dayOfWeekTextAppearance
headerMonthTextAppearance
headerDayOfMonthTextAppearance
headerYearTextAppearance
headerSelectedTextColor
yearListItemTextAppearance
yearListSelectorColor
calendarTextColor
calendarSelectedTextColor
Run Code Online (Sandbox Code Playgroud)
如果您不想要这么多控件(自定义),则无需覆盖datePickerStyle.colorAccent控制大部分DatePicker's颜色.因此,覆盖colorAccent内部MyDatePickerDialogTheme应该工作:
<style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog">
<item name="android:colorAccent">@color/date_picker_accent</item>
<!-- No need to override 'datePickerStyle' -->
<!-- <item name="android:datePickerStyle">@style/MyDatePickerStyle</item> -->
</style>
Run Code Online (Sandbox Code Playgroud)
覆盖还colorAccent为您提供了更改OK和CANCEL文本颜色的额外好处.不错.
这样您就不必向DatePickerDialog's构造函数提供任何样式信息.一切都正确连线:
DatePickerDialog dpd = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
}
}, 2015, 5, 22);
dpd.show();
Run Code Online (Sandbox Code Playgroud)
Nei*_*eil 56
试一试.
代码
new DatePickerDialog(MainActivity.this, R.style.DialogTheme, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
//DO SOMETHING
}
}, 2015, 02, 26).show();
Run Code Online (Sandbox Code Playgroud)
样式在styles.xml文件中
编辑 - 按照建议将主题更改为Theme.AppCompat.Light.Dialog
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/blue_500</item>
</style>
Run Code Online (Sandbox Code Playgroud)
Sid*_*wal 11
创造新风格
<!-- Theme.AppCompat.Light.Dialog -->
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/blue_500</item>
</style>
Run Code Online (Sandbox Code Playgroud)
Java代码:
父主题是这里的关键。选择你的颜色
DatePickerDialog = new DatePickerDialog(context,R.style.DialogTheme,this,now.get(Calendar.YEAR),now.get(Calendar.MONTH),now.get(Calendar.DAY_OF_MONTH);
Run Code Online (Sandbox Code Playgroud)
结果:
小智 6
试试这个,为我工作
放入两个选项,colorAccent然后android:colorAccent
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
....
<item name="android:dialogTheme">@style/AppTheme.DialogTheme</item>
<item name="android:datePickerDialogTheme">@style/Dialog.Theme</item>
</style>
<style name="AppTheme.DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<!-- Put the two options, colorAccent and android:colorAccent. -->
<item name="colorAccent">@color/colorPrimary</item>
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:colorAccent">@color/colorPrimary</item>
</style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
87007 次 |
| 最近记录: |