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>
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
您可能感興趣的文章:
- Android開發(fā)設置RadioButton點擊效果的方法
- Android懸浮按鈕點擊返回頂部FloatingActionButton
- Android Button按鈕的四種點擊事件
- Android開發(fā)-之監(jiān)聽button點擊事件的多種方法
- Android 自定義Button控件實現(xiàn)按鈕點擊變色
- Android中button點擊后字體的變色效果
- Android自定義button點擊效果的兩種方式
- Android開發(fā)之創(chuàng)建可點擊的Button實現(xiàn)方法
- Android實現(xiàn)點擊Button產(chǎn)生水波紋效果
- Android Button點擊事件的四種實現(xiàn)方法
相關文章
Android實現(xiàn)文件按時間先后順序排列顯示的示例代碼
在很多Android應用中,需要管理和展示本地文件,對文件按最后修改時間排序展示,能讓用戶直觀地了解文件的創(chuàng)建或修改順序,從而更方便地查找最新或最舊的文件,本文將介紹如何在Android平臺上獲取指定目錄下的文件列表,并按照時間先后排序,需要的朋友可以參考下2025-04-04
Android三方依賴沖突Gradle中exclude的使用
這篇文章主要介紹了Android三方依賴沖突Gradle中exclude的使用,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-09-09
FFmpeg?Principle學習new_video_stream添加視頻輸出流
這篇文章主要為大家介紹了FFmpeg?Principle學習new_video_stream添加視頻輸出流示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-10-10

