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);
}});