How to change background color of React Native button?

Sometimes, we want to change background color of React Native button.

In this article, we’ll look at how to change background color of React Native button.

How to change background color of React Native button?

To change background color of React Native button, we can set the color prop for Android and we set the backgroundColor for iOS.

For instance, we write:

import * as React from 'react';
import { Button, View, TouchableOpacity, Text } from 'react-native';
import Constants from 'expo-constants';

export default function App() {
  return (
    <View style={{ padding: 30 }}>
      <Button title="Login Android" color="#1E6738" />
      <TouchableOpacity style={{ backgroundColor: '#1E6738' }}>
        <Text style={{ color: '#fff', textAlign: 'center' }}>Login iOS</Text>
      </TouchableOpacity>
    </View>
  );
}

to add <Button title="Login Android" color="#1E6738" /> add a button with the background color set to #1E6738 for Android.

Then for iOS, we write set the backgroundColor on the TouchableOpacity component to add the background color.

And we set the text color in the Text component.

Conclusion

To change background color of React Native button, we can set the color prop for Android and we set the backgroundColor for iOS.