i want to change dynamically generated TouchableOpacity BackgroundColor OnPress in react native.
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.
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.
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.
TouchableOpacity increases the lighteness of a button when tocuhed while TouchableHighlight increases the darkness of a button when touched.
TouchableOpacity modifies the opacity (as its name says it). If you want to change the backgroundcolor on a touch, use TouchableHighlight instead
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With