React-native-picker-select: Picker style is not working

Created on 9 Jun 2018  路  15Comments  路  Source: lawnstarter/react-native-picker-select

RN 0.55.4
"name": "react-native-picker-select",
"version": "3.1.1",

<View style={{flex: 1}} >
    <Text style={{color: '#0082c6', fontSize: 16, fontWeight: 'bold', marginLeft: 5}}>SEXO</Text>
    <RNPickerSelect
        placeholder={{
            label: 'Seu Sexo',
            value: '',
        }}
        items={this.state.items}
        onValueChange={(value) => {
            this.setState({
                sexo: value,
            });
        }}
        style={{ backgroundColor: '#000' }}
    />  
</View>

I've tried to change the style to approximate the Picker box to the label "SEXO" but none type of styling is working. How to fix that?

Image to understand it better: img

Most helpful comment

I use like this:

const pickerStyle = {
    inputIOS: {
        color: 'white',
        paddingTop: 13,
        paddingHorizontal: 10,
        paddingBottom: 12,
    },
    inputAndroid: {
        color: 'white',
    },
    placeholderColor: 'white',
    underline: { borderTopWidth: 0 },
    icon: {
        position: 'absolute',
        backgroundColor: 'transparent',
        borderTopWidth: 5,
        borderTopColor: '#00000099',
        borderRightWidth: 5,
        borderRightColor: 'transparent',
        borderLeftWidth: 5,
        borderLeftColor: 'transparent',
        width: 0,
        height: 0,
        top: 20,
        right: 15,
    },
};

<PickerSelect
    selectedValue={this.state.moreLessSelected}
    placeholder={{}}
    onValueChange={itemValue => this.setState({ moreLessSelected: itemValue })}
    style={pickerStyle}
    items={[
        { label: 'More', value: '>' },
        { label: 'Less', value: '<' },
    ]}
/>

And working good 馃馃徎

All 15 comments

The style object needs nested objects targeting individual parts of the component.

https://github.com/lawnstarter/react-native-picker-select/issues/23

Read through that and let me know if that helps

@lfkwtz I have tried this, but still the same.

Can you share the updated code where you tried that solution?

I use like this:

const pickerStyle = {
    inputIOS: {
        color: 'white',
        paddingTop: 13,
        paddingHorizontal: 10,
        paddingBottom: 12,
    },
    inputAndroid: {
        color: 'white',
    },
    placeholderColor: 'white',
    underline: { borderTopWidth: 0 },
    icon: {
        position: 'absolute',
        backgroundColor: 'transparent',
        borderTopWidth: 5,
        borderTopColor: '#00000099',
        borderRightWidth: 5,
        borderRightColor: 'transparent',
        borderLeftWidth: 5,
        borderLeftColor: 'transparent',
        width: 0,
        height: 0,
        top: 20,
        right: 15,
    },
};

<PickerSelect
    selectedValue={this.state.moreLessSelected}
    placeholder={{}}
    onValueChange={itemValue => this.setState({ moreLessSelected: itemValue })}
    style={pickerStyle}
    items={[
        { label: 'More', value: '>' },
        { label: 'Less', value: '<' },
    ]}
/>

And working good 馃馃徎

@sturmenta it works!

inputAndroid: {
      color: 'white',
  },

How to change item font size in Android? @sturmenta

am going through the same problem,anyone?

I got mine to work with

<RNPickerSelect

                    value={this.props.middleBellLengthType}
                    placeholder={{ label: '...', value: '...'}}

                    style={{inputAndroid:{
                        fontSize: scale(16),
                        justifyContent: 'center',
                        textAlign: 'center',
                        paddingHorizontal: 10,
                        paddingVertical: 8,
                        placeholderColor: '#ababa',
                        borderWidth: 0.5,
                        color: '#ababa',
                        paddingRight: scale(30), // to ensure the text is never behind the icon
                      },},
                      {iconContainer: {
                        placeholderColor: '#ababa',
                        top: scale(2),
                        right: scale(20),
                      },}} 
                    Icon = {() => {return(
                        <Icon.Button
                            name="caret-down"
                            color={'black'}
                            size={scale(15)}
                            style={styles.pauseButton}
                            backgroundColor="transparent"
                            underlayColor="transparent"
                           >
                        </Icon.Button>);
                    }}
                    onValueChange={ . . .

... although the font color seems to change once an item is inputed and set to this.props.middleBellLengthType ...
I just got it to work with
placeholder={{ label: this.props.middleBellLengthType, value: this.props.middleBellLengthType}}

...
style={pickerSelectStyles}
useNativeAndroidPickerStyle={false} // add this line and it should work
/>

@meliodev your solution works!

Might it be a good idea to put the nested object keys inside the documentation somewhere? It's not clear that the key naming convention is strict.

@AlexHooperDev i'm welcome to prs

how can we style the picker list itself? I have tried targeting the styles using these options - inputAndroid, viewContainer, headlessAndroidContainer,inputAndroidContainer - but none of them seem to style the dropdown list.

I am trying to wrap the options on to a new line since the labels are really long.

I use like this:

const pickerStyle = {
  inputIOS: {
      color: 'white',
      paddingTop: 13,
      paddingHorizontal: 10,
      paddingBottom: 12,
  },
  inputAndroid: {
      color: 'white',
  },
  placeholderColor: 'white',
  underline: { borderTopWidth: 0 },
  icon: {
      position: 'absolute',
      backgroundColor: 'transparent',
      borderTopWidth: 5,
      borderTopColor: '#00000099',
      borderRightWidth: 5,
      borderRightColor: 'transparent',
      borderLeftWidth: 5,
      borderLeftColor: 'transparent',
      width: 0,
      height: 0,
      top: 20,
      right: 15,
  },
};

<PickerSelect
  selectedValue={this.state.moreLessSelected}
  placeholder={{}}
  onValueChange={itemValue => this.setState({ moreLessSelected: itemValue })}
  style={pickerStyle}
  items={[
      { label: 'More', value: '>' },
      { label: 'Less', value: '<' },
  ]}
/>

And working good 馃馃徎

How could RNPickerSelect turn to PickerSelect!?

upon selection of the picker view textfield I want to be able to make the textfield bottom border to be blue and thicker and I've tried the bottomBorderColor and width but nothing seems to be changing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

karajaNaji picture karajaNaji  路  3Comments

gregogalante picture gregogalante  路  4Comments

alexborton picture alexborton  路  6Comments

luizParreira picture luizParreira  路  8Comments

Hristijan95 picture Hristijan95  路  4Comments