Android 點擊ImageButton時有“按下”的效果的實現(xiàn)
1為ImageButton添加圖片后,有邊框,看起來像是圖片貼在了一個按扭上面,要多丑有多丑。
解決辦法:ImageButton背景設(shè)為透明:#0000
2.使用Button時為了讓用戶有“按下”的效果,有兩種實現(xiàn)方式:
A.
imageButton.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN){ //更改為按下時的背景圖片 v.setBackgroundResource(R.drawable.pressed); }else if(event.getAction() == MotionEvent.ACTION_UP){ //改為抬起時的圖片 v.setBackgroundResource(R.drawable.released); } return false; } }); B.
<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false" android:drawable="@drawable/button_add" /> <item android:state_pressed="true" android:drawable="@drawable/button_add_pressed" /> <item android:state_focused="true" android:drawable="@drawable/button_add_pressed" /> <item android:drawable="@drawable/button_add" /> </selector>
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答
圖片精選