我已经使用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
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>
答案 0 :(得分:0)
将以下行添加到您的自定义样式中
<item name="android:inputType">textMultiLine</item>
希望这会起作用!