我有 2 个这样的按钮:
Button b = new Button(this);
b.setText("Button onw");
b.setId(1111);
b.setBackgroundDrawable(R.drawable.button);
b.setOnTouchListener(listenerOne);
rootLayout.addView(b);
Button b1 = new Button(this);
b1.setText("Button two");
b1.setBackgroundDrawable(R.drawable.button);
b1.setOnTouchListener(listenerOne);
RelativeLayout.LayoutParams i = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, UIUtils.convertDPToPixels(activity
.getResources().getDisplayMetrics(), 45));
i.addRule(RelativeLayout.BELOW, b.getId());
rootLayout.addView(b1, i);
现在这是我的 onTouch :
OnTouchListener listenerOne = new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
view.getBackground().setColorFilter(Color.parseColor("#B7B2B0"), PorterDuff.Mode.MULTIPLY);
view.invalidate();
break;
case MotionEvent.ACTION_CANCEL:
view.getBackground().clearColorFilter();
view.invalidate();
break;
case MotionEvent.ACTION_UP:
view.getBackground().clearColorFilter();
view.invalidate();
break;
}
return false;
}
};
现在的问题是当我触摸一个按钮时,第二个按钮也会突出显示?为什么这里有什么问题?