我有两个按钮: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
,背景也可以改变,变化是随机的。如何避免第二个按钮更改?
将 onTouchEvent 的代码更改为
int color = button1.getCurrentTextColor();
int r = (color) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 16) & 0xFF;
int a = (color >> 24) & 0xFF;
button1.setTextColor(Color.argb(DOWN_Alpha, r, g, b));
上面
,有些人误解了我的问题,现在我发布所有代码
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
}
}