How to change the <picker> selected value fontSize
I have the picker set up like this
<Picker
iosHeader="Select Country"
mode="dropdown"
selectedValue={this.state.selected}
onValueChange={this.onValueChange.bind(this)}
>
<Item label="中文 (China)" value="key0" />
<Item label="United States" value="key1" />
<Item label="Canada" value="key2" />
<Item label="Germany" value="key3" />
...
</Picker>
and I want to adjust the selected value font size.
I tried adding style={{fontSize: 12}} to the picker tag, but that didn't work.
You have to use prop textStyle for that.
textStyle={{fontSize: 12}}
You mean something like this ? but it's not working for me
<Picker style={styles.picker}
iosHeader="Select one"
mode="dropdown"
textStyle={{fontSize: 12,color:'yellow'}}
selectedValue={this.state.tourDuration}
onValueChange={this.onValueChange.bind(this)}>
<Picker.Item label="One hour" value="1"/>
<Picker.Item label="Two hours" value="2"/>
<Picker.Item label="Three hours" value="3"/>
<Picker.Item label="Four hours" value="4"/>
<Picker.Item label="Five hours" value="5"/>
</Picker>
picker: {
color: '#616161',
borderRadius: 14,
borderWidth: 1,
backgroundColor: '#e2e2e2',
borderBottomWidth: 1 / PixelRatio.get(),
borderTopWidth: 1 / PixelRatio.get(),
borderColor: '#484848',
width: 110,
height:40,
marginRight:16
},
It dose not work on Android
Doesn't work on Android for me either. Any workaround?
textStyle prop has no effect on Android here either
@rolandfromrobin Those props are available only for iOS. Check https://facebook.github.io/react-native/docs/picker.html for Android props
@shivrajkumar I see, thank you. Do you know of any workaround to style the selectedValue text in Android picker?
@rolandfromrobin You can style the items conditionally on selection.
how i set the font size for android picker
@Ashutosh21Nigam NativeBase Picker for android is an implementation of ReactNative Picker. You can check here https://facebook.github.io/react-native/docs/picker.html
Found it! This works for Android. Applying the same transform we use to change the size a <Switch> to the style property of the <Picker> should change the fontSize of the selectedValue:
styles.picker = {
transform: [
{ scaleX: 1.5 },
{ scaleY: 1.5 },
]
}
I have tried Friendly-Robot's solution on Android but the touchable region doesn't scale together with the field.
I do not understand why the downvotes. Does this not work for a majority of people? Here are some screenshots where I use this style to effectively change the font size of my <Picker.Item>, the last one is iOS.
@vinicius-cleves Have you tried setting the height and width of your <Picker> to your desired measurements before increasing the font size?
- Just checked on iOS and the same styling works to change font size as well.
EDIT: Nevermind, just realized I posted this in a component library. Anyway, hope this helps someone with the normal RN library somewhere.
@Friendly-Robot It worked OK for me. I had some extra padding because of it, so I applied a negative margin to fix that. But it's the best solution I've seen.
@Friendly-Robot It worked OK for me. Thanks a lot.
@Friendly-Robot I upvote, this is genius solution
Still on iOS I can't set the font size through the textStyle prop.. Anyone found a solution for this?
Still have problem on Android. textStyle doesn't work at all.
When picker item font size will get supported?
@sankhadeeproy007 the problem still persists, why did you close the issue?