NativeBase icon indicating copy to clipboard operation
NativeBase copied to clipboard

Ask - How to change the color style in Picker?

Open yogieputra8 opened this issue 9 years ago • 21 comments

Hello, So I am using Picker component and try this code

import React, { Component } from 'react';
import { Container, Content, Picker } from 'native-base';

const Item = Picker.Item;​
export default class PickerExample extends Component {

    constructor(props) {
        super(props);
        this.state = {
            selectedItem: undefined,
            selected1: 'key1',
            results: {
                items: []
            }
        }
    }
    onValueChange (value: string) {
        this.setState({
            selected1 : value
        });
    }

    render() {
        return (
            <Container>
                <Content>
                    <Picker
                        iosHeader="Select one"
                        mode="dropdown"
                        selectedValue={this.state.selected1}
                        onValueChange={this.onValueChange.bind(this)}>
                        <Item label="Cats" value="key0" />
                        <Item label="Dogs" value="key1" />
                        <Item label="Birds" value="key2" />
                        <Item label="Elephants" value="key3" />
                   </Picker>
                </Content>
            </Container>
        );
    }
}

From the codes above how can I change the selectedValue color style?

yogieputra8 avatar Dec 04 '16 07:12 yogieputra8

I currently have the same issue on iOS and seems selected item has a fixed color of rgb(0,0,0) which is also the color of my background color of my application. Any hack or fix would be appreciated as itemStyle prop seems to have no effect on Picker Items. Thanks as you provide suggestions

abdulsemiu-atanda avatar Sep 02 '17 20:09 abdulsemiu-atanda

I don't know if you manage to active this, but I changed the selected item color setting an style={{ color: '#ffffff' }} to the Picker.

<Picker iosHeader="Selecione" mode="dropdown" selectedValue={this.state.selected} onValueChange={this.onValueChange.bind(this)} style={{ flex: 1, color: '#445870' }} >

alelfreitas avatar Sep 12 '17 15:09 alelfreitas

we can set style for Picker Item and Picker Item text. We cannot set them selectively as of now. See docs

 <Picker
       iosHeader="Select one"
       mode="dropdown"
       selectedValue={this.state.selected1}
       onValueChange={this.onValueChange.bind(this)}
       itemStyle={{ backgroundColor: 'lightgrey', marginLeft: 0, paddingLeft: 15 }}
       itemTextStyle={{ fontSize: 18, color: 'white' }}
       >

akhil-ga avatar Nov 23 '17 07:11 akhil-ga

@alelfreitas thanks!

codinger41 avatar Aug 05 '18 21:08 codinger41

I tried this following approach:

            <Form>
              <Picker
                itemStyle={{
                  backgroundColor: 'green',
                  marginLeft: 0,
                  paddingLeft: 15
                }}
                itemTextStyle={{ fontSize: 18, color: 'blue' }}
                mode="dropdown"
                note
                onValueChange={this.onValueChange.bind(this)}
                selectedValue={this.state.selected}
                style={{ flex: 1 }}
              >
                <Picker.Item label="Wallet" value="key0" />
                <Picker.Item label="ATM Card" value="key1" />
                <Picker.Item label="Debit Card" value="key2" />
                <Picker.Item label="Credit Card" value="key3" />
                <Picker.Item label="Net Banking" value="key4" />
              </Picker>
            </Form>

And nothing is green or blue on the screen.

OtacilioN avatar Oct 22 '18 22:10 OtacilioN

I tried this following approach:

            <Form>
              <Picker
                itemStyle={{
                  backgroundColor: 'green',
                  marginLeft: 0,
                  paddingLeft: 15
                }}
                itemTextStyle={{ fontSize: 18, color: 'blue' }}
                mode="dropdown"
                note
                onValueChange={this.onValueChange.bind(this)}
                selectedValue={this.state.selected}
                style={{ flex: 1 }}
              >
                <Picker.Item label="Wallet" value="key0" />
                <Picker.Item label="ATM Card" value="key1" />
                <Picker.Item label="Debit Card" value="key2" />
                <Picker.Item label="Credit Card" value="key3" />
                <Picker.Item label="Net Banking" value="key4" />
              </Picker>
            </Form>

And nothing is green or blue on the screen.

You need to use itemStyle for change props for picker item. But here i can change the props of text with this;

 <Picker
            iosHeader="Selecione o País"
            style={{color: colors.white}}
            itemStyle={{ fontFamily: fonts.normal }}
            placeholder="Selecione o País"
            mode="dropdown"
            selectedValue={selectedCountry}
            onValueChange={item => this.setState({ selectedCountry: item })}
          >

I change the color of placeholder then black for white;

leticiamrosa avatar Oct 26 '18 17:10 leticiamrosa

None of the above suggestions worked for me. Is there a method to set the color of the selected text in the dropdown picker?

MehmetKaplan avatar Feb 07 '19 10:02 MehmetKaplan

there is a way to actually change the text color of the Picker ? i mean the color of the items. I tried all of the suggestions above and more than that, together and did set everything to red, and guess what? there is nothing red on my screen, only the default black.

itspauloroberto avatar Feb 27 '19 19:02 itspauloroberto

https://docs.nativebase.io/Components.html#picker-text-and-item-text-styles-headref

SupriyaKalghatgi avatar Feb 28 '19 03:02 SupriyaKalghatgi

@itspauloroberto i have same problem do u find any solution?

sootood avatar Jul 07 '19 06:07 sootood

The example you linked @SupriyaKalghatgi does not seem to work on Android. Is this another iOS only feature of the Picker?

sentry0 avatar Aug 14 '19 01:08 sentry0

I stopped using the Picker supplied by Nativebase entirely and am using the Picker that is supplied by React-Native directly. It is stylable and works identically to the Nativebase Picker presumably because the Nativebase picker is wrapping or extending it.

https://facebook.github.io/react-native/docs/picker.html

I love the Nativebase components but I feel that this is one of the rare examples of them missing the mark.

sentry0 avatar Aug 14 '19 11:08 sentry0

You can use this picker instead: https://wix.github.io/react-native-ui-lib/docs/Picker/

in Picker.item you can customize how each item looks like, like this:

  <Picker.Item key={option.value}
                           value={option}
                           renderItem={(item, props) => {
                             return (
                               <View style={{backgroundColor: 'white'}}>
                                 <View style={styles.choiseStyle}>
                                   <Text style={styles.option}>
                                     {item.label}
                                   </Text>
                                 </View>

                               </View>
                             )
                           }}
              />

Rawan-Eltobgy avatar Jan 22 '20 01:01 Rawan-Eltobgy

Current version of nativebase (v 2.13) allow you can customize on ios only ảnh

bainguyendeveloper avatar May 01 '20 10:05 bainguyendeveloper

WHY only iOS ???

sirajalam049 avatar Jul 04 '20 14:07 sirajalam049

How can I change the color of the arrow in picker. I want it to appear white for dark theme.

pk936 avatar Aug 14 '20 17:08 pk936

I relaize this is not ideal but in order to change the color of the default Android widgets you need to edit the base Android styles.

  1. Open /android/app/src/main/res/values/styles.xml
  2. Add the following line <item name="android:colorControlNormal">#0B536E</item>
  3. Change the color code to your desired color

Your new file should look something like:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:textColor">#000000</item>
        <item name="android:colorControlNormal">#0B536E</item>
    </style>

</resources>

sentry0 avatar Aug 14 '20 18:08 sentry0

@sentry0 It worked ! Thanx.

pk936 avatar Aug 15 '20 05:08 pk936

<Picker style={{color: 'white'}}> <Picker.Item label="Select your country " value={''} />

               try this

pradeepk7053 avatar Aug 27 '20 09:08 pradeepk7053

you can use like this for selected value from PICKER: <Picker.Item color={(this.state.selectedId =='id') ? 'red' : 'grey' } label={'Value'} value={'id'} />

sridix avatar May 01 '21 08:05 sridix