3

Is it possible to center android picker items and selected item? I've searched everywhere, and tried with alignItems:'center' & justifyContent:'center', but items are still aligned left (visible on photos), when I put alignSelf:'center' picker is no longer visible. Anyone have any clues?

    var REPORTS = [
        {name: 'Report 1', id: 'r1'},
        {name: 'Report 2', id: 'r2'},
        {name: 'Report 3', id: 'r3'},
        {name: 'Report 4', id: 'r4'},
        {name: 'Report5', id: 'r5'},
        {name: 'Report6', id: 'r6'}
    ];

    ...
        <Picker style={styles.androidPicker} mode={'dropdown'}
                selectedValue={this.state.report} itemStyle={styles.reports.iosPicker}
                onValueChange={(reportId) => this.onReportChanged(reportId)}>
           {REPORTS.map(function (reports) { 
               return <Picker.Item style={{alignSelf:'center'}} label={reports.name} 
                           value={reports.id} key={reports.name + reports.id}/>;})} </Picker>

    ...

styles:

var styles = StyleSheet.create({
    androidPicker: {
            flex: 1,
            color: '#6D6D6D',
            backgroundColor: '#FFF',
            marginBottom: 20,
            height: 40, 
            alignItems:'center', 
            justifyContent:'center',
            flexDirection: 'row'
        }
})

Here are snapshoots of closed and opened picker:

RN Android Picker closed RN Android Picker opened

Thanks in advance! :)

Vikky
  • 750
  • 8
  • 16
  • Not sure, but have you tried `textAlign: 'center'` – Nader Dabit May 09 '16 at 14:52
  • Yep, on Picker.Item style there is textAlign: 'center', as you can see in code snippet, and it's not doing anything - literally, I've tried to set it on Picker style too, but it throws warning: "Invalid props.style key 'textAlign' supplied to 'Picker" ... :/ – Vikky May 09 '16 at 14:57
  • 1
    You can use native android. Look [there](http://stackoverflow.com/questions/38921492/how-to-style-the-standard-react-native-android-picker) – Max Jan 26 '17 at 13:01
  • Thank you @Max didn't know I can use native android styles :) – Vikky Feb 03 '17 at 12:19

3 Answers3

1

Try :

androidPicker: { color: '#6D6D6D', backgroundColor: '#FFF', marginBottom: 20, height: 40, alignSelf: 'center', justifyContent:'center', }

It worked for me

RemCoding
  • 11
  • 2
1

At first you need to set useNativeAndroidPickerStyle={false} as this will allow you to use some styling props like inputAndroid and inputAndroidContainer, etc. then you can do the necessary styling in those styles.Take a look at the docs here, you'll get the idea.

Ashutosh Tiwari
  • 424
  • 3
  • 13
0

Would you try like below :

var styles = StyleSheet.create({
    androidPicker: {
            color: '#6D6D6D',
            backgroundColor: '#FFF',
            marginBottom: 20,
            height: 40,
            alignSelf: 'stretch', 
            alignItems:'center', 
            justifyContent:'center',
        }
})
Melih Mucuk
  • 6,988
  • 6
  • 37
  • 56
  • Still aligned left :/ tnx for trying anyway! – Vikky May 10 '16 at 08:42
  • 1
    on iOS, there is an itemStyle for picker item, but I think android is missing :) @Vikky – Melih Mucuk May 10 '16 at 08:43
  • 1
    Yeah I know, and it's working perfectly on iOS - I totally agree,that is exactly what is missing here :) but I was thinking - hey, maybe someone else found some workaround or something to get same behavior on android ^^ – Vikky May 10 '16 at 08:49