我正在使用Eclipse來編寫android應用程序。我已經從Form Widgets選項卡添加了一些標準按鈕,併成功地讓他們打開顯示額外按鈕的新窗口。使按鈕看起來按下
我想按下按鈕,改變外觀並在選擇後繼續按下。
我正在使用Eclipse來編寫android應用程序。我已經從Form Widgets選項卡添加了一些標準按鈕,併成功地讓他們打開顯示額外按鈕的新窗口。使按鈕看起來按下
我想按下按鈕,改變外觀並在選擇後繼續按下。
使用按鈕圖像這樣
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@color/transparent" />
<item
android:drawable="@drawable/closebutton" />
</selector>
創建XML文件中值
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="transparent">#00000000</color>
</resources>
可以使用選擇器
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/button_settings" />
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/button_settings" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/button_settings_selected" />
<item android:drawable="@drawable/button_settings" />
</selector>
現在設置在XML按鈕的背景屬性此繪製,現在在編碼時按鈕被按下設置該標誌採取一個布爾標誌,並設置該按鈕的bacground(選擇圖像)並再次單擊重置標誌值並將imageBackground更改爲選擇器,那就是它!
使用ImageButton並更改按鈕的背景。 你可以使用這種圖像取決於你的需要。像這樣https://web.archive.org/web/20160429124711/http://www.devahead.com/blog/2011/08/creating-a-custom-android-button-with-a-resizable-skin/
非常好,正是我以前的樣子。爲了更好地理解這些差異,我將與所有三者一起討論。非常感謝您的快速和有益的答案。 – Markus
你需要[切換按鈕(http://developer.android添加顏色的文件夾。 com/reference/android/widget/ToggleButton.html) –