How to create a Button with Transparent Background in React Native

Buttons with transparent backgrounds can add a sleek and modern touch to your mobile application. In this blog post, let’s learn how to create a button with a transparent background in react native using the TouchableOpacity component.

TouchableOpacity is a component in react native that is used to wrap a view that should respond to touches. It provides a way to add touch event handlers to a view, and it also provides a way to change the opacity of the view when it is being pressed.

We can change the background color of the button by applying a style to the TouchableOpacity component. We make the value of the backgroundColor style property transparent.

See the code given below.

import React from 'react';
import {StyleSheet, TouchableOpacity, Text, View} from 'react-native';

const App = () => {
  return (
    <View style={styles.container}>
      <TouchableOpacity
        style={styles.button}
        onPress={() => console.log('pressed')}>
        <Text> Transparent Button</Text>
      </TouchableOpacity>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: 'white',
    justifyContent: 'center',
    alignItems: 'center',
  },
  button: {
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'transparent',
    borderRadius: 8,
    padding: 5,
    height: 40,
    borderWidth: 1,
    borderColor: 'green',
  },
});

export default App;

And you will get the following output.

react native transparent button

That’s how you add a button with transparent background in react native.

Leave a Reply

%d bloggers like this: