3

btn1、の 2 つのボタンがあります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

    }
}

2 番目のボタン: btn2、背景も変更される場合があり、変更はランダムです。2番目のボタンの変更を回避するには?

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 に答える