简体   繁体   English

react-native-dropdown-picker 按条件更改下拉背景颜色

[英]react-native-dropdown-picker changing dropdown background color by condition

We are using react-native-dropdown-picker.我们正在使用 react-native-dropdown-picker。

 <DropDownPicker items={timeList.map(item => { return ({ label: item.timeslot, value: item.timeslot }) })} defaultValue={timeList[0].timeslot} placeholder={"Select date"} containerStyle={styles.dropDownContainer} itemStyle={{ justifyContent: "flex-start" }} dropDownStyle={{ backgroundColor: colors.white }} dropDownMaxHeight={hp("45%")} onChangeItem={item => timeSelected(item.value)} arrowSize={30} arrowStyle={{ position: "absolute", right: 0 }} labelStyle={{ fontSize: wp('3.5%'), fontFamily: constants.themeFont, textAlign: 'left', color: '#000', alignSelf: 'center', }} />

So the dropdown's background color has been set from 'dropDownStyle' property.所以下拉菜单的背景颜色是从“dropDownStyle”属性设置的。 I have given the color white.我给了白色。

Let's say, in the 'timeList' (array)variable, I have a key 'enabled' (boolean value) on every object on the array.假设,在“timeList”(数组)变量中,我在数组上的每个 object 上都有一个键“启用”(布尔值)。 So I want to give different background colors for different values(true/ false) of the key 'enabled'.所以我想为“启用”键的不同值(真/假)提供不同的背景 colors。

The 'dropDownStyle' is the common property for all the values on the dropdown. “dropDownStyle”是下拉列表中所有值的通用属性。 So how to change the background color based on every item attribute.那么如何根据每个项目属性更改背景颜色。

Check this out 看一下这个

    {
  ...
  containerStyle: {
    backgroundColor: "#000"
  },
  labelStyle: {
    color: "#fff"
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在“react-native-dropdown-picker”中设置默认值 - Set default value in 'react-native-dropdown-picker' react-native-dropdown-picker 列出的项目未正确显示(覆盖) - react-native-dropdown-picker listed items not showing properly (Overlay) 如何在 react-native-dropdown-picker 中调整模型大小 - How to resize Model in react-native-dropdown-picker 有没有办法将下拉选择器中每个条目的 numberOfLines 设置为 1? (react-native-dropdown-picker) - Is there a way to set numberOfLines to 1 of each entry in the dropdown picker? (react-native-dropdown-picker) react-native-dropdown-picker,如何修复下拉选择器覆盖在其他组件上 - react-native-dropdown-picker, how to fix the dropdown picker overlay on other component 有没有办法降低下拉选择器的高度(react-native-dropdown-picker 模块) - Is there a way to decrease the height of dropdown picker (react-native-dropdown-picker module) react-native-dropdown-picker,如何从项目中获取选定的索引 - react-native-dropdown-picker, how to get selected index from Items 使用颜色选择器更改 React 中下拉项的颜色 - Change color of dropdown item in React with color picker 如何更改下拉箭头的背景颜色 - react-native-material-dropdown-v2-fixed - How to change the background color of dropdown arrow - react-native-material-dropdown-v2-fixed 如何从下拉选择器 React Native 中显示和选择项目 - How to show and select items from a dropdown picker React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM