How to style the React-native picker items to wrap the lengthy text?

霸气de小男生 提交于 2019-12-25 02:55:08

问题


I have designed a picker using react native, and I'm trying to style it using styles.XML BUT its not working. I want my drop down items to wrap in second line when the length of the text exceeds the width.

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

Styles.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>

回答1:


Add below line into your custom style

<item name="android:inputType">textMultiLine</item>

Hope this will work!



来源:https://stackoverflow.com/questions/55120972/how-to-style-the-react-native-picker-items-to-wrap-the-lengthy-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!