0
我想壓制,並且不使用任何圖像釋放時,突出一個按鈕,所以我用從一個下面的代碼後的SO,但它不是爲我工作:選中一個按鈕:爲setColor文件管理器不工作
public class MainActivity extends Activity {
ImageButton myButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myButton = (ImageButton) findViewById(R.id.button);
myButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(myButton));
}
public class ButtonHighlighterOnTouchListener implements OnTouchListener {
final ImageButton imageButton;
public ButtonHighlighterOnTouchListener(final ImageButton imageButton) {
super();
this.imageButton = imageButton;
}
@Override
public boolean onTouch(final View view, final MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
//grey color filter, you can change the color as you like
imageButton.setColorFilter(Color.parseColor("#5F2444"));
System.out.println("called down");
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
imageButton.setColorFilter(Color.parseColor("#245F30"));
System.out.println("called up");
}
return false;
}
}
這裏有什麼問題?
原帖是在這裏:How to make Button highlight?
你需要點擊/懸停效果? – Abhi 2013-04-26 17:16:10
@Abhi你好哥們,我需要點擊效果好友 – Goofy 2013-04-26 17:17:06
爲什麼你不簡單使用選擇器? – Abhi 2013-04-26 17:17:46