我已經在這裏做了深入的研究,並嘗試了很多沒有成功的事情。這裏是我的代碼:Android - 無法更改按鈕狀態背景更改
btn_estoque.xml
<item android:drawable="@drawable/estoque_menu_ativo" android:state_enabled="false"></item>
<item android:drawable="@drawable/estoque_menu" android:state_pressed="false"></item>
<item android:drawable="@drawable/estoque_menu_ativo" android:state_pressed="true"></item>
按鈕代碼:
<Button
android:id="@+id/estoque_menu"
android:background="@drawable/btn_estoque"
android:layout_width="@dimen/tab_button_width"
android:layout_height="@dimen/tab_button_height"
style="?android:attr/buttonBarButtonStyle"
android:contentDescription="@null"
android:onClick="estoqueClick"/>
在類:
public void estoqueClick(View v) {
btnEstoque.setEnabled(false);
Intent intent = new Intent(v.getContext(), EstoqueActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
}
我缺少什麼?當我點擊按鈕時,圖像僅在按下按鈕時才改變。
EDITED
這可能是一些生命週期問題嗎?該按鈕變爲所需的圖像,但稍後返回到原稿。
嘗試增加:'<項目機器人:可繪製=「@ drawable/drawable_id「android:state_enabled =」true「>' –
感謝朋友,但沒有工作。 – Elder