gpt4 book ai didi

android - 如何使用 android styles.xml 设置 react-native 选择器的样式?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:59:31 24 4
gpt4 key购买 nike

我想知道如何设置 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 等通过 native android 完成。

不幸的是,我不是本地 Android 开发人员,所以我无法理解解决方案。我将以下代码 fragment 添加到/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>

就是这样:)

关于android - 如何使用 android styles.xml 设置 react-native 选择器的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38976064/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com