Ask - How to change the color style in Picker?
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?
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
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' }} >
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' }}
>
@alelfreitas thanks!
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.
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;
None of the above suggestions worked for me. Is there a method to set the color of the selected text in the dropdown picker?
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.
https://docs.nativebase.io/Components.html#picker-text-and-item-text-styles-headref
@itspauloroberto i have same problem do u find any solution?
The example you linked @SupriyaKalghatgi does not seem to work on Android. Is this another iOS only feature of the Picker?
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.
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>
)
}}
/>
Current version of nativebase (v 2.13) allow you can customize on ios only

WHY only iOS ???
How can I change the color of the arrow in picker. I want it to appear white for dark theme.
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.
- Open /android/app/src/main/res/values/styles.xml
- Add the following line
<item name="android:colorControlNormal">#0B536E</item> - 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 It worked ! Thanx.
<Picker style={{color: 'white'}}> <Picker.Item label="Select your country " value={''} />
try this
you can use like this for selected value from PICKER: <Picker.Item color={(this.state.selectedId =='id') ? 'red' : 'grey' } label={'Value'} value={'id'} />