3

我有两个按钮:btn1, btn2。它们与相同的背景图像一起使用:pic1.png. 当我更改第一个按钮的背景时:btn1OnTouch事件中,代码如下

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,背景也可以改变,改变是随机的。如何避免第二个按钮变化?

4

2 回答 2

0

将 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));
于 2012-11-22T07:37:44.503 回答
0

以上,有些人误解了我的问题,现在我贴出所有代码

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

    }
}
于 2012-11-22T09:36:23.730 回答