我是android编程的新手,当我想添加一组单选按钮无法正确显示文本和单选按钮混合时你可以看到图片了解我的意思:
这是我的简单代码,我希望你能帮助我,非常感谢你
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gRadio">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="@+id/rB1" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="@+id/rB2" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
android:id="@+id/rB3" />
</RadioGroup>
</LinearLayout>
答案 0 :(得分:0)
现在好了。我犯了一个错误,我使用 sdk版本8 在IDE中渲染我的布局,尽管我的 编译SDK版本API 23 ,谢谢大家。
答案 1 :(得分:0)
因此,对于这种情况,有一种治疗方法。
1。尝试使用AppCompatRadioButton 设置自定义样式,该样式从 @android:style / Widget.Holo.CompoundButton.RadioButton 延伸 具有以下属性
“buttonTint” 和值 @ color / red
“android:button” 和值 @ drawable / custom_radio_selector
2。添加两个图像绘图,一个用于检查,另一个用于未检查状态。
3. 创建自定义可绘制选择器“custom_radio_selector.xml”
<item android:state_checked="true" android:state_pressed="true"
android:drawable="@drawable/ic_radio_on" />
<item android:state_checked="false" android:state_pressed="true"
android:drawable="@drawable/ic_radio_off" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/ic_radio_on" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/ic_radio_off" />
<item android:state_checked="false" android:drawable="@drawable/ic_radio_off" />
<item android:state_checked="true" android:drawable="@drawable/ic_radio_on" />
其中 ic_radio_off.png 和 ic_radio_on.png 是根据需要添加的图片绘图。