Android Radio Button自定义Drawable不生效问题求助
Android分段式单选按钮自定义Drawable效果不符问题
我在Android开发中使用RadioButton组件,为其配置了选中与未选中状态的自定义Drawable,期望实现分段式单选按钮效果,但当前运行效果与预期不符。
相关代码
RadioGroup布局代码
<RadioGroup android:id="@+id/segmented2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_margin="6dp" android:layout_weight="1" android:baselineAligned="false" android:orientation="horizontal"> <RadioButton android:id="@+id/colorRadioButton" style="@style/RadioButton" android:layout_width="wrap_content" android:layout_height="match_parent" android:checked="true" android:text="@string/color_color" /> <RadioButton android:id="@+id/gradientRadioButton" style="@style/RadioButton" android:layout_width="wrap_content" android:layout_height="match_parent" android:checked="false" android:text="@string/color_gradient" android:visibility="visible" /> </RadioGroup>
RadioButton样式(style/RadioButton)
<style name="RadioButton" parent="Base.Widget.AppCompat.CompoundButton.RadioButton"> <item name="android:gravity">center_vertical|center</item> <item name="android:paddingLeft">10dp</item> <item name="android:paddingRight">20dp</item> <item name="android:background">@null</item> <item name="android:button">@drawable/radio_checked_unchecked</item> <item name="android:minWidth">70dp</item> <item name="android:minHeight">35dp</item> </style>
Drawable选择器(drawable/radio_checked_unchecked.xml)
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/radio_checked" android:state_checked="true"/> <item android:drawable="@drawable/radio_unchecked"/> </selector>
内容的提问来源于stack exchange,提问作者Mayur
相关产品推荐
相关产品推荐

