我有两个按钮:btn1
, btn2
。它们与相同的背景图像一起使用:pic1.png
. 当我更改第一个按钮的背景时:btn1
在OnTouch
事件中,代码如下
onTouch_Action(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
TextView tv = (TextView) v;
int color = tv.getCurrentTextColor();
int r = (color) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 16) & 0xFF;
int a = (color >> 24) & 0xFF;
tv.setTextColor(Color.argb(50, r, g, b)); //The other uses the same background image buttons may also change
} else if (event.getAction() == MotionEvent.ACTION_UP) {
int color = tv.getCurrentTextColor();
int r = (color) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 16) & 0xFF;
int a = (color >> 24) & 0xFF;
tv.setTextColor(Color.argb(255, r, g, b)); //The other uses the same background image buttons may also change
}
}
第二个按钮:btn2
,背景也可以改变,改变是随机的。如何避免第二个按钮变化?