Nativescript Datepicker更改文本颜色 [英] Nativescript Datepicker change text color

查看:56
本文介绍了Nativescript Datepicker更改文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在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中,也只能通过Reflection 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 (请参阅注释此处了解详情)

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆