如何在React Native中更改TimePickerAndroid的颜色?

时间:2016-09-20 16:44:39

标签: react-native timepicker react-native-android

是否可以更改TimePickerAndroid组件的默认颜色?

enter image description here

2 个答案:

答案 0 :(得分:7)

你必须从android的styles.xml文件中更改它。这是你做的:

1)打开styles.xml:" android / app / src / main / res / values / styles.xml" 2)您需要添加几行:

<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:timePickerDialogTheme">@style/Dialog.Theme</item>
</style>

<style name="Dialog.Theme" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#FF0000</item>
    <item name="android:textColorPrimary">#0000FF</item>
</style>

在styles.xml中,您应该已经拥有:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

如果你只是添加剩余的行。如果没有继续添加它们。

4)最后,重新编译应用程序。 &#34; react-native run-android&#34;。您应该立即看到颜色变化。

答案 1 :(得分:0)

使用React-native,遗憾的是没有。

但是,通过更改RN中的一些java文件并使用this solution from SO,您可以执行此操作。 如果您成功完成此操作,我建议您在RN的存储库上创建一个Pull Request,因为它可能对其他用户非常有用。 您也可以通过NPM将其开发为模块和开源。