Android 點(diǎn)擊ImageButton時(shí)有“按下”的效果的實(shí)現(xiàn)
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ì)本站的支持!
- Android開(kāi)發(fā)設(shè)置RadioButton點(diǎn)擊效果的方法
- Android懸浮按鈕點(diǎn)擊返回頂部FloatingActionButton
- Android Button按鈕的四種點(diǎn)擊事件
- Android開(kāi)發(fā)-之監(jiān)聽(tīng)button點(diǎn)擊事件的多種方法
- Android 自定義Button控件實(shí)現(xiàn)按鈕點(diǎn)擊變色
- Android中button點(diǎn)擊后字體的變色效果
- Android自定義button點(diǎn)擊效果的兩種方式
- Android開(kāi)發(fā)之創(chuàng)建可點(diǎn)擊的Button實(shí)現(xiàn)方法
- Android實(shí)現(xiàn)點(diǎn)擊Button產(chǎn)生水波紋效果
- Android Button點(diǎn)擊事件的四種實(shí)現(xiàn)方法
相關(guān)文章
Android Studio中配置OpenCV庫(kù)開(kāi)發(fā)環(huán)境的教程
這篇文章主要介紹了Android Studio中配置OpenCV庫(kù)開(kāi)發(fā)環(huán)境的教程,OpenCV有Java接口,因而也經(jīng)常被用來(lái)做安卓開(kāi)發(fā),需要的朋友可以參考下2016-05-05代碼分析Android實(shí)現(xiàn)側(cè)滑菜單
現(xiàn)在app越來(lái)越注重用戶體驗(yàn),本文給大家分析android實(shí)現(xiàn)側(cè)滑菜單的代碼,代碼簡(jiǎn)單易懂,感興趣的朋友一起看看吧2015-11-11Android中Image的簡(jiǎn)單實(shí)例詳解
這篇文章主要為大家詳細(xì)介紹了Android中Image的簡(jiǎn)單實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12Android實(shí)現(xiàn)手勢(shì)滑動(dòng)多點(diǎn)觸摸放大縮小圖片效果
這篇文章主要介紹了Android實(shí)現(xiàn)手勢(shì)滑動(dòng)多點(diǎn)觸摸放大縮小圖片效果的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-02-02