单选按钮仅被部分选中
Radio Button is only partially checked
我知道这听起来很奇怪所以这是图片。
它持有正确的价值。 (部分)选择了正确的单选按钮。 OnCheckedChangeListener
中的所有逻辑都正确执行。我完全惊呆了。为什么单选按钮没有完全选中?
我唯一能想到的就是我正在使用 Rx2Firebase
periodRetriever = FirebaseHelper.getInstance(getContext()).getPeriod()
.defaultIfEmpty(0)
.distinctUntilChanged()
.subscribe(new Consumer<Integer>() {
@Override
public void accept(@NonNull Integer headerType) throws Exception {
getRadioViewChecked(headerType).setChecked(true);
}
});
EDIT1
Marcos 建议我看不到白色勾号。不是这种情况。
EDIT2
布局:
<RadioGroup
android:id="@+id/rgPeriod"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/rbMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/month" />
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/rbWeek"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/week" />
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/rb4Weeks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/four_weeks" />
</RadioGroup>
您的主题是深色,您看不到白色勾号,您需要将其更改为其他颜色。
尝试更改您的主题或单选按钮的颜色属性
将背景颜色从白色更改为另一种颜色
您是否尝试过使用 RadioButton
而不是 android.support.v7.widget.AppCompatRadioButton
我认为这可能会解决问题
另一方面,您可以在此处找到有关如何设置 RadioButtons 样式的文档
http://www.materialdoc.com/radio-button/
- 在您的 styles.xml 文件中声明自定义样式。
<style name="MyRadioButton" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">@color/indigo</item>
<item name="colorControlActivated">@color/pink</item>
</style>
- 通过 android:theme 属性将此样式应用于您的 RadioButton。
`
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Radio Button"
android:theme="@style/MyRadioButton"/>
来源:
看起来像一个动画错误。在 ViewPager 内的 Fragment 上使用 CompoundButton 时,可绘制状态设置不正确。
复选框也会出现这种情况,如下所示:。
在调用 RadioGroup.check(id) 或 Checkbox.setChecked(true) 之后调用 jumpDrawablesToCurrentState() 似乎可以解决问题(thx @Dalmas)
除了@Nipper 的出色回答,我在我的项目中写了一个 Kotlin 扩展来轻松解决问题:
fun CompoundButton.setCheckedFixed(checked: Boolean) {
isChecked = checked
jumpDrawablesToCurrentState()
}
我应该在任何地方做 radioButton.isChecked = true
或 radioButton.setChecked(true)
而不是 radioButton.setCheckedFixed(true)
.
我知道这听起来很奇怪所以这是图片。
它持有正确的价值。 (部分)选择了正确的单选按钮。 OnCheckedChangeListener
中的所有逻辑都正确执行。我完全惊呆了。为什么单选按钮没有完全选中?
我唯一能想到的就是我正在使用 Rx2Firebase
periodRetriever = FirebaseHelper.getInstance(getContext()).getPeriod()
.defaultIfEmpty(0)
.distinctUntilChanged()
.subscribe(new Consumer<Integer>() {
@Override
public void accept(@NonNull Integer headerType) throws Exception {
getRadioViewChecked(headerType).setChecked(true);
}
});
EDIT1
Marcos 建议我看不到白色勾号。不是这种情况。
EDIT2
布局:
<RadioGroup
android:id="@+id/rgPeriod"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/rbMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/month" />
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/rbWeek"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/week" />
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/rb4Weeks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="@string/four_weeks" />
</RadioGroup>
您的主题是深色,您看不到白色勾号,您需要将其更改为其他颜色。
尝试更改您的主题或单选按钮的颜色属性
将背景颜色从白色更改为另一种颜色
您是否尝试过使用 RadioButton
而不是 android.support.v7.widget.AppCompatRadioButton
我认为这可能会解决问题
另一方面,您可以在此处找到有关如何设置 RadioButtons 样式的文档
http://www.materialdoc.com/radio-button/
- 在您的 styles.xml 文件中声明自定义样式。
<style name="MyRadioButton" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">@color/indigo</item>
<item name="colorControlActivated">@color/pink</item>
</style>
- 通过 android:theme 属性将此样式应用于您的 RadioButton。
`
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Radio Button"
android:theme="@style/MyRadioButton"/>
来源:
看起来像一个动画错误。在 ViewPager 内的 Fragment 上使用 CompoundButton 时,可绘制状态设置不正确。
复选框也会出现这种情况,如下所示:
在调用 RadioGroup.check(id) 或 Checkbox.setChecked(true) 之后调用 jumpDrawablesToCurrentState() 似乎可以解决问题(thx @Dalmas)
除了@Nipper 的出色回答,我在我的项目中写了一个 Kotlin 扩展来轻松解决问题:
fun CompoundButton.setCheckedFixed(checked: Boolean) {
isChecked = checked
jumpDrawablesToCurrentState()
}
我应该在任何地方做 radioButton.isChecked = true
或 radioButton.setChecked(true)
而不是 radioButton.setCheckedFixed(true)
.