【发布时间】:2019-05-20 00:08:18
【问题描述】:
我想知道它是否可能以编程方式以及在检查时如何以编程方式更改 RadioButton 的颜色?
PS : 我不想使用 XML
在 XML 中,我使用类似的东西及其工作:
<RadioButton
android:id="@+id/radio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test1"
android:textColor="@color/red"
android:textSize="16dp"
android:paddingStart="10dp"
android:paddingEnd="0dp"
android:theme="@style/CustomColorRadioButton" />
在我的 style.xml 中
<style name="CustomRadioButton" parent="AppTheme">
<item name="colorControlActivated">@color/blue</item>
</style>
如何以编程方式做到这一点?
【问题讨论】:
-
radioButton.setBackgroundColor(getResources().getDrawable(R.color.yourColor));
-
这个用XML,我不想用