欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 點擊ImageButton時有“按下”的效果的實現(xiàn)

 更新時間:2017年03月19日 15:52:48   投稿:lqh  
這篇文章主要介紹了 Android 點擊ImageButton時有“按下”的效果的實現(xiàn)的相關資料,需要的朋友可以參考下

 Android 點擊ImageButton時有“按下”的效果的實現(xiàn)

1為ImageButton添加圖片后,有邊框,看起來像是圖片貼在了一個按扭上面,要多丑有多丑。

解決辦法:ImageButton背景設為透明:#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>  

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關文章

最新評論