Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在创建一个 MCQ 应用程序,其中有四个选项Buttons。最初所有按钮的颜色都是默认颜色。每当用户单击正确答案时,背景颜色将Button变为绿色,并且当用户单击错误选项时,背景颜色将Button变为红色和以绿色显示正确答案Button。之后,用户单击下一个问题按钮。现在我想将所有选项的背景颜色更改Buttons为其初始状态,即默认颜色。我不知道该怎么做。请帮助我将按钮图像更改为其默认颜色/图像。
Buttons
Button
在 NEXT BUTTON 的 onClick() 中放置代码以将选项按钮颜色更改为您选择的颜色。
onClick() { button.setBackgroundColor(color); }
默认颜色不是颜色,它是许多 9-patch 图像的 StateListDrawable 我建议您将选项按钮的按钮背景设置为白色,然后在按下 NEXT 按钮时将其设置回白色。