[英]react-native picker using android styles.xml for change font-family not changed
[英]How to style the react-native picker using android styles.xml?
我想知道如何設置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>
我在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>
而已 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.