我想知道如何设置fontFamily.如何设置颜色和Picker.items上的背景颜色?
<Picker style={styles.picker} // cannot set fontFamily here selectedValue={this.state.selected2} onValueChange={this.onValueChange.bind(this,'selected2')} mode="dropdown"> <Item label="hello" value="key0" /> // cannot set backgroundColor here <Item label="world" value="key1" /> </Picker>
我posted this on Github并得到了答案,只有一些属性可以通过样式在React Native中设置,但选择器的一些更核心的元素(如使用的字体)是由原生Android驱动的.它需要通过使用styles.xml等的本机android来完成.
不幸的是,我不是一个原生的Android开发人员,所以我无法理解解决方案.我将以下代码段添加到/res/values/styles.xml,但弹出窗口的文本颜色或背景没有更改.
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> </style> <style name="SpinnerItem"> <item name="android:textColor">#ffffff</item> <item name="android:background">#993399</item> </style> <style name="SpinnerDropDownItem"> <item name="android:textColor">#ffffff</item> <item name="android:background">#993399</item> </style> </resources>
我需要做出哪些其他改变?如何设置fontFamily?
解决方法
那是因为您需要在AppTheme中声明样式
<resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="android:spinnerItemStyle">@style/SpinnerItem</item> <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item> </style> <style name="SpinnerItem"> <item name="android:textColor">#ffffff</item> <item name="android:background">#993399</item> </style> <style name="SpinnerDropDownItem"> <item name="android:textColor">#ffffff</item> <item name="android:background">#993399</item> </style> </resources>
而已 :)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。