Android 點(diǎn)擊ImageButton時(shí)有“按下”的效果的實(shí)現(xiàn)
1為ImageButton添加圖片后,有邊框,看起來(lái)像是圖片貼在了一個(gè)按扭上面,要多丑有多丑。
解決辦法:ImageButton背景設(shè)為透明:#0000
2.使用Button時(shí)為了讓用戶有“按下”的效果,有兩種實(shí)現(xiàn)方式:
A.
imageButton.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN){ //更改為按下時(shí)的背景圖片 v.setBackgroundResource(R.drawable.pressed); }else if(event.getAction() == MotionEvent.ACTION_UP){ //改為抬起時(shí)的圖片 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>
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選