我創建Android應用程序,當用戶在應用程序 按鈕圖像應該改變「以顯示其已被按下」那麼一些功能是使用被稱爲的Android按鈕背景變化
點擊一個按鈕在的onclick功能如下代碼:
{
btn.setBackgroundDrawable(getResources().getDrawable(R.drawable.sync_active));
sync();
}
會發生什麼是同步功能被稱爲第一,該按鈕圖像的變化!
我創建Android應用程序,當用戶在應用程序 按鈕圖像應該改變「以顯示其已被按下」那麼一些功能是使用被稱爲的Android按鈕背景變化
點擊一個按鈕在的onclick功能如下代碼:
{
btn.setBackgroundDrawable(getResources().getDrawable(R.drawable.sync_active));
sync();
}
會發生什麼是同步功能被稱爲第一,該按鈕圖像的變化!
所有你需要的是使用Android這樣的選擇器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="false"
android:drawable="@drawable/btn_red" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/btn_orange" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/btn_orange" />
<item
android:state_enabled="true"
android:drawable="@drawable/btn_black" />
</selector>
而在onClick()
方法;你只需要調用你的函數sync()
,
指這個偉大tutorial它正是你想要的:)
在繪製文件夾
<?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/greencolorbutton" />
<item
android:drawable="@drawable/closebutton" />
</selector>
使用這樣的按鈕圖像與mybutton.xml創建XML文件,並使用該按鈕的XML代碼
android:background:@drawable/mybutton
檢查
你可以嘗試把同步()函數中的線程。
但是...你可以試驗一下,看看會發生什麼。如果您認爲出現意想不到的事情,您可以提出一個更準確的問題來提供您的結果 –