Nativescript Datepicker 更改文本颜色 [英] Nativescript Datepicker change text color
问题描述
我正在尝试将 Android 中的日期选择器颜色更改为白色.我试过在styles.xml中使用colorPrimary但没有运气:
I'm trying to change the datepicker color to white in Android. I've tried with colorPrimary in styles.xml with no luck:
<style name="AppTheme" parent="AppThemeBase">
<item name="android:datePickerStyle">@style/SpinnerDatePicker</item>
</style>
<style name="SpinnerDatePicker" parent="android:Widget.Material.Light.DatePicker">
<item name="colorPrimary">#FFF</item>
<item name="android:datePickerMode">spinner</item>
</style>
另外,有没有办法在一个组件中使用一种颜色,然后在一秒钟内使用另一种颜色,或者我一定要为整个应用程序使用一种颜色?
Also, is there a way to use one color in a component and another in a second or am I bound to use one color for the whole app?
推荐答案
你不能动态改变 DatePicker 的颜色...至少它不是一件微不足道的工作.问题是,即使在原生 Android 中,通过代码隐藏更改颜色也只能通过反射 API 来实现(请参阅此处详情).
You can't change the color of the DatePicker dynamically... at least it is not a trivial job. The thing is that even in native Android changing the color via code-behind can be achieved only with the Reflection API (see here for details).
要更改 DatePicker 的文本颜色,需要注意一件重要的事情 - 您应该在主 应用主题直接应用android:textColorPrimary
strong>(查看评论此处了解详情)
To change the text color of the DatePicker there is one important thing to notice - you should apply android:textColorPrimary
directly in the main app theme (see the comments here for details)
例如:values-v21/style.xml
For example: values-v21/style.xml
<style name="AppTheme" parent="AppThemeBase">
<item name="android:textColorPrimary">@color/ns_green</item> <!-- HERE -->
<item name="android:datePickerStyle">@style/SpinnerDatePicker</item>
<item name="android:timePickerStyle">@style/SpinnerTimePicker</item>
</style>
在上面的例子中,ns_green
是在 colors.xml
In the example above ns_green
is defined in colors.xml
<color name="ns_green">#1eb234</color>
这篇关于Nativescript Datepicker 更改文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!