React Native:更改 Paper Button 中的文本颜色

Kha*_*inn 8 react-native react-native-paper

我对 React Native 比较陌生。

我可以轻松地显示按钮(带有阴影等),如下所示。

 <Button
  mode="contained"
  color={'#f08e25'}
  contentStyle={{ height: 44 }}
  onPress={this.onPressSubmit}
  theme={theme} >SUBMIT </Button>
Run Code Online (Sandbox Code Playgroud)

我也参考了这个文档。

https://callstack.github.io/react-native-paper/button.html#contentStyle

问题是如果模式是“包含”,我无法更改文本颜色。我在 contentStyle 或 theme 中尝试过,但它不起作用。如果模式是“包含”,我该如何更改文本颜色?

Tea*_*amo 18

对于mode="contained"react-native-paper按钮,color更改背景颜色,您需要labelStyle更改文本。对于mode="flat"按钮,color将更改文本。您只需要添加labelStyle道具即可。下面的代码将为您提供带有白色文本的橙色按钮,例如:

<Button
  mode="contained"
  color="#f08e25"
  contentStyle={{ height: 44 }}
  labelStyle={{ color: "white", fontSize: 18 }}
  onPress={this.onPressSubmit}
  theme={theme} >
    SUBMIT 
</Button>
Run Code Online (Sandbox Code Playgroud)

  • 有没有办法做到主题明智?即如果您希望所有按钮的 labelStyle 颜色设置为白色。 (2认同)

小智 4

import * as React from 'react';
import { Button,Text } from 'react-native-paper';

const MyComponent = () => (
  <Button icon="camera" color="blue" dark={true} compact={true}  style={{color:"red",marginTop:100}} mode="contained" onPress={() => console.log('Pressed')}>
   <Text style={{color:"red"}}>press me</Text>
  </Button>
);

export default MyComponent;
Run Code Online (Sandbox Code Playgroud)

这是您在包含模式下的答案,颜色显示所有按钮的颜色,而不仅仅是文本的颜色