React Native 更改按钮文本颜色

Posted

技术标签:

【中文标题】React Native 更改按钮文本颜色【英文标题】:React Native change Button Text color 【发布时间】:2021-05-23 21:10:15 【问题描述】:

我是 React Native 的初学者,我想在其中编写第一行代码。我做了一个按钮,开始想知道如何更改按钮中文本的颜色和其他属性。 <Button title="Click Me"></Button>

我还想知道是否有一些推荐给初学者的好包。感谢您的帮助。

【问题讨论】:

【参考方案1】:

您可以像这样使用 react-native 中的 Button,也可以传递 color 属性。

Button
  onPress=onPressLearnMore
  title="Click Me"
  color="#841584"
/>

对于复杂和自定义按钮,您可以使用 react-native 提供的 Touchables 以您自己的样式创建它,您不必为此使用任何第三方库。

例子:

    <TouchableOpacity style= here you can specify custom styles for button container  onPress=gotoDashboard>
        <Text style=here you can specify text styles>Button Text Here</Text>
  // You can add there as many components according to your designs.
      </TouchableOpacity>

【讨论】:

第一个代码不会改变文本颜色。 按钮组件没有更改文本颜色的选项。 color 属性只是改变了 Button 的整体背景颜色。您必须将 Touchable 用于自定义按钮。试试第二个例子。我希望这会锻炼

以上是关于React Native 更改按钮文本颜色的主要内容,如果未能解决你的问题,请参考以下文章