2
我正在开发一个问题游戏,如果答案正确,我想将答案按钮的背景颜色更改为绿色;如果答案错误,只是在用户按下按钮的时候,我会将其更改为红色。如何动态更改按下按钮的背景颜色?
其实我有我分配到的按钮布局中custom_button.xml:
<Button
android:id="@+id/la"
android:width="63dp"
android:height="65dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/la"
android:tag="@string/la"
android:layout_toRightOf="@+id/fa"
**android:background="@drawable/custom_button"**
android:layout_margin="3dp"
/>
有没有办法更改按钮的按下背景只是在当下用户按下按钮?
我试过在按钮OnClickListener中使用setBackgroundDrawable(),但这改变了按钮的行为,下次用户单击按钮时,不是实际的。
bt.setBackgroundDrawable(getResources().getDrawable(R.drawable.custom_button_fail));
在此先感谢!
+1,感谢名单了很多crisitian,你在我心中的SetBackgroundResource方法制成的光,我是不知道有关相同。感谢名单 – 2011-02-28 06:47:01