admin管理员组文章数量:1410682
In mobile apps, it is critical to show some sort of indication that the user has touched a specific element, especially when trying to touch an element that will redirect. Hence, I was hoping to change the background colour of touchableOpacity
element on touch, and then return back to the original background colour.
For example, if the user touches this element:
The background colour is changed on touch.
How do I do this in touchableOpacity
?
<TouchableOpacity
style={[styles.verticalCenter, styles.floatRight]}
activeOpacity={1.0}
underlayColor="rgba(253,138,94,0)"
onPress={()=> this.openModal()}
>
<Ionicons name="log-out" size={16} color="#bccad0" />
</TouchableOpacity>
floatRight: {
flex: 1,
alignItems: 'center',
borderWidth: 1,
borderColor: 'rgba(0,0,0,0.2)',
justifyContent: 'center',
width: 30,
height: 30,
backgroundColor: '#fff',
borderRadius: 100 / 2,
},
The above just doesn't work.
Any help would be appreciated.
In mobile apps, it is critical to show some sort of indication that the user has touched a specific element, especially when trying to touch an element that will redirect. Hence, I was hoping to change the background colour of touchableOpacity
element on touch, and then return back to the original background colour.
For example, if the user touches this element:
The background colour is changed on touch.
How do I do this in touchableOpacity
?
<TouchableOpacity
style={[styles.verticalCenter, styles.floatRight]}
activeOpacity={1.0}
underlayColor="rgba(253,138,94,0)"
onPress={()=> this.openModal()}
>
<Ionicons name="log-out" size={16} color="#bccad0" />
</TouchableOpacity>
floatRight: {
flex: 1,
alignItems: 'center',
borderWidth: 1,
borderColor: 'rgba(0,0,0,0.2)',
justifyContent: 'center',
width: 30,
height: 30,
backgroundColor: '#fff',
borderRadius: 100 / 2,
},
The above just doesn't work.
Any help would be appreciated.
Share Improve this question edited Jan 21, 2018 at 22:12 user555121 asked Jan 21, 2018 at 22:10 S. NasS. Nas 3311 gold badge5 silver badges14 bronze badges2 Answers
Reset to default 3Use TouchableHighlight instead of TouchableOpacity
<TouchableHighlight
activeOpacity={0.6}
underlayColor="#DDDDDD"
onPress={() => alert('Pressed!')}>
<MyComponent />
</TouchableHighlight>;
If you set activeOpacity={0.2}
it will make the background lighter. As you are setting opacity to 1 it doesn't change on click.
本文标签: javascriptHow to briefly change the background color on touch in react nativeStack Overflow
版权声明:本文标题:javascript - How to briefly change the background color on touch in react native? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745047911a2639474.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论