• <small id='D4F31'></small><noframes id='D4F31'>

    <i id='D4F31'><tr id='D4F31'><dt id='D4F31'><q id='D4F31'><span id='D4F31'><b id='D4F31'><form id='D4F31'><ins id='D4F31'></ins><ul id='D4F31'></ul><sub id='D4F31'></sub></form><legend id='D4F31'></legend><bdo id='D4F31'><pre id='D4F31'><center id='D4F31'></center></pre></bdo></b><th id='D4F31'></th></span></q></dt></tr></i><div id='D4F31'><tfoot id='D4F31'></tfoot><dl id='D4F31'><fieldset id='D4F31'></fieldset></dl></div>

        <legend id='D4F31'><style id='D4F31'><dir id='D4F31'><q id='D4F31'></q></dir></style></legend>
        <tfoot id='D4F31'></tfoot>

        • <bdo id='D4F31'></bdo><ul id='D4F31'></ul>
      1. 在 React Native 中更改 TouchableOpacity 的颜色

        Change color of TouchableOpacity in React Native(在 React Native 中更改 TouchableOpacity 的颜色)

            • <bdo id='cFLgl'></bdo><ul id='cFLgl'></ul>
                  <tbody id='cFLgl'></tbody>

                <small id='cFLgl'></small><noframes id='cFLgl'>

                • <i id='cFLgl'><tr id='cFLgl'><dt id='cFLgl'><q id='cFLgl'><span id='cFLgl'><b id='cFLgl'><form id='cFLgl'><ins id='cFLgl'></ins><ul id='cFLgl'></ul><sub id='cFLgl'></sub></form><legend id='cFLgl'></legend><bdo id='cFLgl'><pre id='cFLgl'><center id='cFLgl'></center></pre></bdo></b><th id='cFLgl'></th></span></q></dt></tr></i><div id='cFLgl'><tfoot id='cFLgl'></tfoot><dl id='cFLgl'><fieldset id='cFLgl'></fieldset></dl></div>
                  <legend id='cFLgl'><style id='cFLgl'><dir id='cFLgl'><q id='cFLgl'></q></dir></style></legend>

                • <tfoot id='cFLgl'></tfoot>
                  本文介绍了在 React Native 中更改 TouchableOpacity 的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  谁能帮帮我.这是我的源代码:https://snack.expo.io/rJFgyPDpH

                  Can anyone help me. This is my source code: https://snack.expo.io/rJFgyPDpH

                  想法是,如果我点击1 Button"它应该是红色",如果我点击2 Button"也应该改变它的颜色为红色",但 "1 Button" 应更改为其默认颜色,即黑色.但是,2 按钮".

                  Idea is that, if I click to "1 Button" it should be 'red' and if I click to "2 Button" is also should change its color to 'red' but the "1 Button" should be changed to its default colour which is black. However, "2 Button".

                  如果我的方法过于简单,也欢迎使用其他方法(如TouchableHighlight、ES6 等).如果您向我展示错误以便我从中吸取教训,我将不胜感激.

                  If my approach is too simple, other methods (such as TouchableHighlight, ES6 and etc) are also welcomed. I appreciate if you show me mistakes so that I learn from that.

                  推荐答案

                  你可以这样写代码:

                  import React, {Component} from 'react';
                  import {Platform, StyleSheet, Text, View, Button,TouchableOpacity} from 'react-native';
                  
                  export default class App extends Component {
                    state={
                      backgroundColor: 'black',
                      backgroundColor2: 'black',
                      pressed: false,
                    };
                  
                    changeColor(){
                      if(!this.state.pressed){
                         this.setState({ pressed: true,backgroundColor: 'red', backgroundColor2: 'black'});
                      } else {
                        this.setState({ pressed: false, backgroundColor: 'black' ,backgroundColor2: 'red'});
                      }
                    }
                    render() {
                      return (
                        <View style={styles.container}>
                            <TouchableOpacity
                                style={{backgroundColor:this.state.backgroundColor, padding: 15}}
                                onPress={()=>this.changeColor()}
                                  >
                              <Text style={styles.text}>1 Button</Text>
                            </TouchableOpacity>
                  
                            <TouchableOpacity
                                style={{backgroundColor:this.state.backgroundColor2, padding: 15}}
                                onPress={()=>this.changeColor()}
                                  >
                              <Text style={styles.text}>2 button!</Text>
                            </TouchableOpacity>
                  
                        </View>
                      );
                    }
                  }
                  
                  const styles = StyleSheet.create({
                    text:{
                      color:'white'
                      },
                    container: {
                      flex: 1,
                      justifyContent: 'center',
                      alignItems: 'center',
                      backgroundColor: '#fff',
                    },
                  });
                  

                  现在,如果您单击第一个按钮,它应该是红色",但第二个按钮仍然是黑色"背景.因此,如果您点击第二个按钮,它应该是红色",而第一个按钮应该是黑色".

                  Now If you click to the first button it should be 'red', but second, remains as 'black' background. Consequently, if you click to second button it should be 'red', whereas the first button should be 'black'.

                  这篇关于在 React Native 中更改 TouchableOpacity 的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                • <legend id='6VEpE'><style id='6VEpE'><dir id='6VEpE'><q id='6VEpE'></q></dir></style></legend>

                    <tbody id='6VEpE'></tbody>

                    <tfoot id='6VEpE'></tfoot>
                  1. <i id='6VEpE'><tr id='6VEpE'><dt id='6VEpE'><q id='6VEpE'><span id='6VEpE'><b id='6VEpE'><form id='6VEpE'><ins id='6VEpE'></ins><ul id='6VEpE'></ul><sub id='6VEpE'></sub></form><legend id='6VEpE'></legend><bdo id='6VEpE'><pre id='6VEpE'><center id='6VEpE'></center></pre></bdo></b><th id='6VEpE'></th></span></q></dt></tr></i><div id='6VEpE'><tfoot id='6VEpE'></tfoot><dl id='6VEpE'><fieldset id='6VEpE'></fieldset></dl></div>
                      <bdo id='6VEpE'></bdo><ul id='6VEpE'></ul>

                      • <small id='6VEpE'></small><noframes id='6VEpE'>