列表项上的背景色不起作用?

时间:2019-09-28 17:08:34

标签: react-native background-color listitem react-native-elements

我是第一次制作列表项,如果使用此代码,则没有发现任何变化:

**编辑!

     import React from "react";
import { StyleSheet, View } from "react-native";
import { ListItem } from "react-native-elements";
import MaterialIcons from "react-native-vector-icons/MaterialIcons";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";

export default class ChangePassword extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  accountIcon = () => (
    <MaterialIcons name="account-box" size={35} type="MaterialIcons" />
  );
  changePasswordIcon = () => (
    <MaterialCommunityIcons
      name="textbox-password"
      size={35}
      type="MaterialCommunityIcons"
    />
  );

  render() {
    return (
      <View>
        <ListItem title="Account" leftIcon={this.accountIcon} bottomDivider />
        <View style={{ backgroundColor: "#007bff" }}>
          <ListItem
            title="Change password"
            leftIcon={this.changePasswordIcon}
            bottomDivider
          />
        </View>
      </View>
    );
  }
}


有人可以向我解释为什么会这样,我该如何解决。

感谢,感谢您的宝贵时间

1 个答案:

答案 0 :(得分:0)

您正在使用react-native-elements。因此,您必须使用该模块的样式。

您可以使用containerStyle={{backgroundColor:""}}

如果您只想更改标题的颜色,请titleStyle={{backgroundColor:""}}

示例

          <ListItem
            title="Change password"
            leftIcon={this.changePasswordIcon}
            bottomDivider
            containerStyle={{backgroundColor:"blue"}}
            titleStyle={{backgroundColor:"red"}}
          />
相关问题