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

问题描述 投票:0回答:1

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

**编辑!

     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>
    );
  }
}


有人可以向我解释这是为什么,请问如何解决此问题。

感谢,谢谢您的时间

react-native background-color listitem react-native-elements
1个回答
0
投票

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

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

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

实施例

          <ListItem
            title="Change password"
            leftIcon={this.changePasswordIcon}
            bottomDivider
            containerStyle={{backgroundColor:"blue"}}
            titleStyle={{backgroundColor:"red"}}
          />
© www.soinside.com 2019 - 2024. All rights reserved.