【问题标题】:How to style the React-native picker items to wrap the lengthy text?如何设置 React-native 选择器项目的样式以包装冗长的文本?
【发布时间】:2019-08-02 21:29:25
【问题描述】:

我已经使用 react native 设计了一个选择器,我正在尝试使用 styles.XML 对其进行样式设置,但它不起作用。 当文本的长度超过宽度时,我希望我的下拉项目在第二行中换行。

class PickerExample extends Component {
   state = {link: ''}
   updateUser = (link) => {
      this.setState({ link: link })
   }
   render() {
      return (
         <View>
            <Picker selectedValue = {this.state.user} onValueChange = {this.updateUser}>
               <Picker.Item label = "25 best small-business apps in 2018 - nerdwallet" value = "one" />
               <Picker.Item label = "Top business apps, best apps for small business" value = "two" />
               <Picker.Item label = "Collaboration & productivity apps for business" value = "three" />
            </Picker>
            <Text style = {styles.text}>{this.state.link}</Text>
         </View>
      )
   }
}
export default PickerExample

样式.xml

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
        <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
    </style>

    <style name="SpinnerItem" parent="Theme.AppCompat.Light.NoActionBar">>
        <item name="android:fontFamily">segoe-ui</item>
    </style>

    <style name="SpinnerDropDownItem" parent="Theme.AppCompat.Light.NoActionBar">>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>   
        <item name="android:singleLine">false</item>
    </style>

</resources>

【问题讨论】:

    标签: android react-native picker


    【解决方案1】:

    将下面的行添加到您的自定义样式中

    &lt;item name="android:inputType"&gt;textMultiLine&lt;/item&gt;

    希望这会奏效!

    【讨论】:

    • 我应该把这个自定义样式放在哪里?
    猜你喜欢
    • 2016-12-19
    • 2020-12-27
    • 1970-01-01
    • 2017-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-03
    相关资源
    最近更新 更多