小编Ati*_*buj的帖子

有没有办法从反应本机选择器组件中删除默认填充?

我想从一开始就显示选择器组件内的文本,而不应用任何填充。我研究过但找不到解决方案。我正在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)

padding styling picker react-native

4
推荐指数
2
解决办法
7090
查看次数

标签 统计

padding ×1

picker ×1

react-native ×1

styling ×1