ImageView设置选中变暗效果。
public final float[] BT_SELECTED = new float[] {1,0,0,0,99,0,1,0,0,99,0,0,1,0,99,0,0,0,1,0}; public final float[] BT_NOT_SELECTED = new float[] {1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0};; public final static float[] BT_SELECTED1 = new float[] { 0.338f, 0.339f, 0.332f, 0, 0, 0.338f, 0.339f, 0.332f, 0, 0, 0.338f, 0.339f, 0.332f, 0, 0, 0, 0, 0, 1, 0 }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView ib2; ib1 = (ImageView) findViewById(R.id.imageViewt); ib2 = (ImageView) findViewById(R.id.imageView2); ib1.setOnTouchListener(new ImageView.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { ib1.setImageResource(R.drawable.icon1); ib1.getDrawable().setColorFilter( new ColorMatrixColorFilter(BT_SELECTED)); ib1.setImageDrawable(ib1.getDrawable()); } else if (event.getAction() == MotionEvent.ACTION_UP) { ib1.getDrawable().clearColorFilter(); ib1.getDrawable().setColorFilter(new ColorMatrixColorFilter(BT_NOT_SELECTED)); ib1.setImageResource(R.drawable.icon2); } return false; } }); }