更改DatePicker [Xamarin.Forms]的颜色 [英] change the colour of DatePicker [Xamarin.Forms]
本文介绍了更改DatePicker [Xamarin.Forms]的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在显示日历视图时,是否可以更改DatePicker控件的背景颜色?请检查随附的屏幕截图.
is there any way to change the background colour of the DatePicker control while showing a calendar view? Please check the attached screenshot.
推荐答案
将以下内容添加到您的style.xml文件中:
Add the following to your style.xml file:
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#2196F3</item>
</style>
完整的XML:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="MyTheme" parent="MyTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
<item name="windowActionBar">false</item>
<!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette-->
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#2196F3</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#2196F3</item>
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">#2196F3</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#2196F3</item>
</style>
<style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
<item name="android:headerBackground">#2196F3</item>
</style>
<style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog">
<item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
</style>
更新
时间选择器:
<style name="Theme.MyTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:timePickerDialogTheme">@style/TimePickerDialogTheme</item>
然后设置timePickerDialogTheme并设置timePickerStyle:
Then set the timePickerDialogTheme and set the timePickerStyle:
<style name="TimePickerDialogTheme" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#ff6d3024</item>
<item name="android:timePickerStyle">@style/TimePickerDialogStyle</item>
现在您可以创建style.xml:
Now you can create the style.xml:
<style name="TimePickerDialogStyle" parent="@android:style/Widget.Material.Light.TimePicker">
<item name="colorAccent">#ff6d3024</item>
<item name="android:timePickerMode">clock</item>
<item name="android:headerBackground">#ff6d3024</item>
<item name="android:headerTimeTextAppearance">@style/TextAppearance.TimePickerDialogStyle.TimeLabel</item> <!-- TimePicker Time *TextAppearance* -->
<item name="android:numbersTextColor">#ff000000</item>
<item name="android:numbersSelectorColor">#ff6d3024</item>
<item name="android:numbersBackgroundColor">#ffdddddd</item>
这篇关于更改DatePicker [Xamarin.Forms]的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文