在 react-native 中覆盖按钮 backgroundColor

Overwrite a button backgroundColor in react-native

我是 react-native 的新手,我想知道是否有一种简单的方法可以覆盖按钮中的 backgroundColor。我确实尝试了很多方法,但没有运气。 基本上我试图用我的自定义颜色替换默认的蓝色背景。

有什么好的建议吗?

请仔细阅读 Button 在 React Native 中的文档,

您可以轻松地为 Button 的颜色属性提供所需的颜色,如下所示:

<Button
        title="Press me"
        color="black" // Color of your choice
        onPress={() => Alert.alert('Button with adjusted color pressed')}>

你可以试试

function App() {
  const [color,setColor] = React.useState('blue'); 

  return (
    <Button 
       color={color}
       title="Click here"  
       onPress={() => { setColor("black") } />
    </div>
  );
}

export default App;