NativeBase icon indicating copy to clipboard operation
NativeBase copied to clipboard

How to change the <picker> selected value fontSize

Open evansque opened this issue 9 years ago • 29 comments

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.

evansque avatar Jan 07 '17 21:01 evansque

You have to use prop textStyle for that.

textStyle={{fontSize: 12}}

sankhadeeproy007 avatar Jan 12 '17 14:01 sankhadeeproy007

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
    },

nimabk82 avatar Feb 22 '17 10:02 nimabk82

It dose not work on Android

YKSing avatar Jul 30 '17 02:07 YKSing

Doesn't work on Android for me either. Any workaround?

crest-ccruz avatar Aug 18 '17 17:08 crest-ccruz

textStyle prop has no effect on Android here either

rolandfromrobin avatar Sep 11 '17 11:09 rolandfromrobin

@rolandfromrobin Those props are available only for iOS. Check https://facebook.github.io/react-native/docs/picker.html for Android props

shivrajkumar avatar Sep 11 '17 11:09 shivrajkumar

@shivrajkumar I see, thank you. Do you know of any workaround to style the selectedValue text in Android picker?

rolandfromrobin avatar Sep 11 '17 11:09 rolandfromrobin

@rolandfromrobin You can style the items conditionally on selection.

shivrajkumar avatar Sep 11 '17 12:09 shivrajkumar

how i set the font size for android picker

Ashutosh21Nigam avatar Apr 18 '18 03:04 Ashutosh21Nigam

@Ashutosh21Nigam NativeBase Picker for android is an implementation of ReactNative Picker. You can check here https://facebook.github.io/react-native/docs/picker.html

akhil-ga avatar Apr 18 '18 13:04 akhil-ga

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 },
  ]
}

azanli avatar May 11 '18 23:05 azanli

I have tried Friendly-Robot's solution on Android but the touchable region doesn't scale together with the field.

vinicius-cleves avatar Sep 12 '18 19:09 vinicius-cleves

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.

screenshot_20180912-140758 screenshot_20180912-140732 img_0737

azanli avatar Sep 12 '18 21:09 azanli

@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.

reabbotted avatar Oct 03 '18 23:10 reabbotted

@Friendly-Robot It worked OK for me. Thanks a lot.

rfdss avatar Oct 23 '18 00:10 rfdss

@Friendly-Robot I upvote, this is genius solution

Fr33maan avatar Nov 14 '18 12:11 Fr33maan

Still on iOS I can't set the font size through the textStyle prop.. Anyone found a solution for this?

gtiongco95 avatar Apr 04 '19 02:04 gtiongco95

Still have problem on Android. textStyle doesn't work at all.

mdeveloper20 avatar May 11 '19 06:05 mdeveloper20

When picker item font size will get supported?

wadeem avatar Jul 04 '19 08:07 wadeem

@sankhadeeproy007 the problem still persists, why did you close the issue?

evansque avatar Jul 04 '19 08:07 evansque