Change button background color on press in
Is there an way to change the color of the Button while the user is pressing it? Currently, its possible to make it more transparent, but not change the color.
Button is wrapped around TouchableOpacity, so setting onPress background color is not possible at the moment. I recommend the use of TouchableHighlight for your desired effect.
Hi, would like to change background color when button press too. Do you guys have any plan to implement using TouchableHighlight? Initially, I wanted to clone the same button using TouchableHighlight, but it seems like there are alot logics and libraries in the Button widget.
We have added this to our roadmap. We will implement this in future versions.
Added in latest release.
Please, how do I do this?
Hi @sankhadeeproy007 ,
How can i add overlay to touchable highlight
import React, { Component, StyleSheet, PropTypes, View, Text, TouchableHighlight } from "react-native";
export default class Home extends Component {
constructor(props) {
super(props);
this.state = { pressStatus: false };
}
_onHideUnderlay=()=> {
this.setState({ pressStatus: false });
}
_onShowUnderlay=()=> {
this.setState({ pressStatus: true });
}
render() {
return (
Home.propTypes = { text: PropTypes.string.isRequired };
const styles = StyleSheet.create({ container: { flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "#F5FCFF" }, welcome: { fontSize: 20, textAlign: "center", margin: 10, color: "#000066" }, welcomePress: { fontSize: 20, textAlign: "center", margin: 10, color: "#ffffff" }, button: { borderColor: "#000066", borderWidth: 1, borderRadius: 10 }, buttonPress: { borderColor: "#000066", backgroundColor: "#000066", borderWidth: 1, borderRadius: 10 } });
@ajuajas Use underlayColor and activeOpacity
<TouchableHighlight
onPress={() => console.log("button pressed')}
activeOpacity={0.6}
underlayColor="#DDDDDD">
<Text>
{"press me"}
</Text>
</TouchableHighlight>
Button is wrapped around
TouchableOpacity, so setting onPress background color is not possible at the moment. I recommend the use ofTouchableHighlightfor your desired effect.
We have added this to our roadmap. We will implement this in future versions.
@sankhadeeproy007 @himanshu-satija : Have we got any updates on this as an in-built prop for a Button native base component in the latest versions?
this solution it work for me <Button _pressed={{backgroundColor: "#fff"}} w={width ? width : '100%'} size="lg" _text={{ color: theme.colors.white, fontSize: 'lg', fontFamily: 'bold', }} ref={myRef} onPress={onPress}> {title}
Do we have any update on this ?