React Native Color属性不起作用

问题描述 投票:-1回答:3

Blockquote

code

   <Text style ={styles.header}>
     Flex
   </Text>

   header: {
    justifyContent: 'center',
    alignSelf: 'center',
    fontWeight: 'bold',
    marginTop: 55,
    color: 'red',
  }

问题color属性没有改变,Text的所有属性都在起作用,而不是color

react-native react-native-android
3个回答
0
投票

像这样更改style

<Text h1 style={styles.header}>

应该工作


0
投票

您需要使用style而不是h1style。由于没有名为h1style的道具。请参考下面的代码

import React, { Component } from "react";
import { StyleSheet, Text } from "react-native";

class App extends Component {
  render() {
    return (
      <Text h1 style={styles.header}>
        Flex
      </Text>
    );
  }
}

const styles = StyleSheet.create({
  header: 
    justifyContent: "center",
    alignSelf: "center",
    fontWeight: "bold",
    marginTop: 55,
    color: "#13E5F5"
  }
});

export default App;

[更多的帮助,请在线检查codesandbox上的相同代码

enter image description here


0
投票

h1style在react native中不是有效的道具名称。您需要使用style而不是h1style

<Text h1 style={styles.header}>
© www.soinside.com 2019 - 2024. All rights reserved.