简体   繁体   English

自定义 react-native-dropdown-picker 中的元素

[英]Customize elements in react-native-dropdown-picker

React Native Dropdown Picker is the most popular library to implement a dropdown in React Native. React Native Dropdown Picker是在 React Native 中实现下拉列表的最流行的库。 But in the library, I could not find a way to customize the dropdown arrow and the ticks in the dropdown list.但是在库中,我找不到自定义下拉列表中的下拉箭头和刻度的方法。 They are by default in black color and cannot be customized with my knowledge.它们默认为黑色,据我所知无法自定义。

Basic implementation:基本实现:

 import DropDownPicker from 'react-native-dropdown-picker'; function App() { const [open, setOpen] = useState(false); const [value, setValue] = useState(null); const [items, setItems] = useState([ { label: 'ice-cream', value: '1' }, { label: 'strawberry', value: '2' }, { label: 'grapes', value: '3' }, { label: 'fruit salad', value: '4' }, { label: 'jello', value: '5' }, { label: 'apple', value: '6' }, ]); return ( <DropDownPicker open={open} value={value} items={items} setOpen={setOpen} setValue={setValue} setItems={setItems} /> ); }

Sample Output: [Click here to see the output] 2示例 Output: [单击此处查看输出] 2

There is a prop in the called arrowIconStyle .有一个道具叫做arrowIconStyle But for that also, I could not find a way to give a color as a style.但就此而言,我也找不到将颜色作为样式的方法。

Ex: arrowIconStyle={{color: 'white'}}例如: arrowIconStyle={{color: 'white'}}

Unfortunately this does not work and gives an error: 

Type '{ color: string;输入'{颜色:字符串; }' is not assignable to type 'StyleProp'.ts(2322) }' 不可分配给类型 'StyleProp'.ts(2322)

Can someone please help me regarding this?有人可以帮我解决这个问题吗?

Thank you.谢谢你。

尝试更改箭头图标并为图标实现您自己的样式,如下所示: https ://snack.expo.dev/@hewr/57a779

//to change the dropdown box style
dropDownContainerStyle={{
  backgroundColor: "#dfdfdf"
}}

// to style the selected item style
selectedItemContainerStyle={{
   backgroundColor: "grey"
}}

for more details visit their website有关详细信息,请访问他们的网站

and check the Dropdown and List and Items sections并检查DropdownList and Items部分

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM