Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在*按下另一个按钮时*更改视图_Android - Fatal编程技术网

Android 在*按下另一个按钮时*更改视图

Android 在*按下另一个按钮时*更改视图,android,Android,我想知道 当按下另一个视图时,如何更改该视图的属性 例如,当按下另一个按钮时,文本视图会改变其颜色?为按下的视图注册一个,并更改方法中文本视图的属性。这里有一个演示 在爪哇 这只是一个例子: TextView txt1 = (TextView) findViewById(R.id.text1); TextView txt2 = (TextView) findViewById(R.id.text2); 还有一个按钮 Button btn = (Button) findViewById(

我想知道 当按下另一个视图时,如何更改该视图的属性

例如,当按下另一个按钮时,文本视图会改变其颜色?

为按下的
视图注册一个,并更改方法中
文本视图的属性。

这里有一个演示 在爪哇

这只是一个例子:

TextView txt1 = (TextView) findViewById(R.id.text1);
  TextView  txt2 = (TextView) findViewById(R.id.text2);
还有一个按钮

 Button  btn = (Button) findViewById(R.id.button1);

btn.setOnClickListener(new OnClickListener() 
        {
            public void onClick(View back_button)
            {
txt1.setBackgroundColor(Color.BLACK);
txt2.setBackgroundColor(Color.BLACK);
}});

点击按钮后,文本视图的背景色变为黑色。对其他属性尝试这样做

我在按下按钮时说,什么时候我会在这里更改它?请阅读文档。您将在
onTouch
方法中收到s。这样的
MotionEvent
s有不同的动作,例如和,你可以检测到并相应地采取行动。事实上,我是在我的评论之后读到的:)你应该在回答中更详细一些
 Button  btn = (Button) findViewById(R.id.button1);

btn.setOnClickListener(new OnClickListener() 
        {
            public void onClick(View back_button)
            {
txt1.setBackgroundColor(Color.BLACK);
txt2.setBackgroundColor(Color.BLACK);
}});