【android開發筆記】如何讓ImageButton去掉白色邊框和讓ImageButton具有點選效果
阿新 • • 發佈:2018-12-04
這是我從網上學來的,怕忘記,遂記起來
如何讓ImageButton去掉白色邊框
android:background="#00000000" //把背景變透明
放在那一段程式碼裡呢?放在layout裡面的.xml檔案裡
如:
效果自己試一下<ImageButton android:id="@+id/down" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/surfaceView" android:layout_toRightOf="@+id/left" android:background="#00000000" //放這裡 android:src="@drawable/id_down" />
然後說到讓ImageButton具有點選效果,這個和上面就是最佳配合了
當然這個也有很多方法,我就覺得這個比較適合我
首先我們準備兩張圖片
(left)-----1 半透明
(left2)------2 不透明
也可以弄不同顏色
這裡以1為預設顯示,2是點選才顯示的
把圖片放進drawable-hdpi裡面,新建資料夾來存放將要用的是檔案drawable,然後在這個資料夾裡面新建一個.xml檔案id_left(名字可自己命名)。裡面寫上下面程式碼:
<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/left2" /> <item android:state_focused="true" android:drawable="@drawable/left2" /> <item android:drawable="@drawable/left" /> </selector>
然後在layout裡的.xml裡面加上
然後就可以了,看效果圖<ImageButton android:id="@+id/left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/down" android:layout_alignLeft="@+id/surfaceView" android:background="#00000000" android:src="@drawable/id_left" /> //這裡
這個是沒有按的
這個是按下去的效果
舉一反三其它也可以這樣!!!