React Native - 标记和样式中参数之间的差异

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

我正在尝试使用React-native更改按钮的背景颜色。

我无法弄清楚为什么会这样

<Button
 color="#841584"
 title={item.title}
/>

但事实并非如此

<Button
  style={styles.buttonStyle}
  color="#841584"
  title={item.title}
/>

const styles = StyleSheet.create({
    buttonStyle: {
        color:"#841584"
    }
});

我尝试使用colorbackgroundColor属性,但它们都不起作用

为什么这些彼此不同?

button react-native
1个回答
1
投票

反应原生的Button成分没有style道具。因此,您提供的风格不适用。

道具

  • onPress
  • 标题
  • accessibilityLabel
  • 颜色
  • 测试
  • hasTVPreferredFocus

它基本上是一个内置于react-native的自定义组件。你可以使用TouchableOpacityTouchableNativeFeedback创建你的。为了获得灵感,你可以看看source code for Button component

© www.soinside.com 2019 - 2024. All rights reserved.