Ati*_*buj 4 padding styling picker react-native
我想从一开始就显示选择器组件内的文本,而不应用任何填充。我研究过但找不到解决方案。我正在android中调试。
我的代码:
<View style={[styles.pickerContainer]}>
<Picker
selectedValue={this.state.phoneCountryCode}
style={[styles.pickerText(text),{backgroundColor:'transparent', width: 80 }]}
itemStyle={{padding:0, backgroundColor:'yellow'}}
mode="dropdown"
onValueChange={(itemValue, itemIndex) =>
this.setState({ phoneCountryCode: itemValue })
}>
{Constants.CountryCodes.map((item, index) => (
<Picker.Item key={item} label={item.label} value={item.value} />
))}
</Picker>
</View>
Run Code Online (Sandbox Code Playgroud)
风格:
pickerContainer:{
marginTop: 10,
position: 'absolute', left:0, bottom:0, zIndex:10,
},
pickerText:(text)=>({
color:'gray',
height: 40,
textAlign: 'left',
padding:0,
margin: 0,
}),
Run Code Online (Sandbox Code Playgroud)
免责声明:适用于 Android,我不知道它是否适用于 IOS。
就我而言,将边距设置为-16(因为选择器的填充设置为 16)并使用 style: 中设置的以下内容将选择器包装到视图中就足够了overflow: 'hidden', justifyContent: 'center', display: 'flex'。现在可以通过在视图上设置填充来设置填充。顺便说一句,设置视图高度也适用于选择器。
<View
style={{
width: '70%',
borderStyle: 'solid',
borderWidth: 1,
borderColor: 'black',
height: 20,
padding: 6,
overflow: 'hidden',
justifyContent: 'center',
display: 'flex',
}}>
<Picker
mode="dropdown"
style={{
backgroundColor: 'yellow',
margin: -16,
}}
onValueChange={(itemValue, itemIndex) => {}}>
<Picker.Item label="Java" value="java" style={{fontSize: 10}} />
<Picker.Item label="JavaScript" value="js" style={{fontSize: 10}} />
</Picker>
</View>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7090 次 |
| 最近记录: |