Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change touchableopacity backgroundColor on button press react native

i want to change dynamically generated TouchableOpacity BackgroundColor OnPress in react native.

like image 907
Developer Avatar asked Oct 22 '18 13:10

Developer


People also ask

How do I change TouchableOpacity color on press?

As per your requirements, onPress on first button, it will invoke changeColor. And onPress of second button, it'll invoke changeColor2. In the code, onPress of second button, it can be changed to changeColor2 instead of changeColor function.

How do I change the background color when click on button in react native?

To change background color on click in React:Set the onClick prop on the element. When the element is clicked, set the active state. Use a ternary operator to conditionally set the background color based on the state variable.

How do you style TouchableOpacity in react native?

To create custom buttons, you need to customize the <TouchableOpacity /> component and include the <Text /> component inside of it to display the button text. const AppButton = ({ onPress, title }) => ( <TouchableOpacity onPress={onPress} style={styles. appButtonContainer}> <Text style={styles.

What is difference between TouchableOpacity and TouchableHighlight?

TouchableOpacity increases the lighteness of a button when tocuhed while TouchableHighlight increases the darkness of a button when touched.


1 Answers

TouchableOpacity modifies the opacity (as its name says it). If you want to change the backgroundcolor on a touch, use TouchableHighlight instead

like image 156
Guillaume Piedigrossi Avatar answered Sep 23 '22 17:09

Guillaume Piedigrossi