我已经设计了一个使用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
style.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>
在您的自定义样式中添加以下行
<item name="android:inputType">textMultiLine</item>
希望这会起作用!
<Picker
selectedValue={gender}
style={GlobalStyles.picker}
numberOfLines={3} // use this number of lines attribute .it works file in android
>
<Picker.Item
label={item.label}
value={item.value}
key={item.label}
fontFamily="Raleway-Medium"
style={GlobalStyles.pickerText}
/>
</Picker>