【发布时间】:2010-10-24 17:19:46
【问题描述】:
我正在开发一个问题游戏,我想在用户按下按钮的那一刻将按下答案按钮的背景颜色更改为绿色(如果答案正确)或红色(如果答案错误)。
实际上我有一个 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));
提前致谢!
【问题讨论】:
标签: android