有人能告诉我如何创建一个带有单选按钮的radioGroup,其外观与图像类似:
这是我的xml代码:
<RadioGroup
android:id="@+id/network_creation_radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="20dp">
<RadioButton
android:id="@+id/network_creation_private"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:drawableRight="@drawable/lock"
android:text="Private"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
style="@style/TextView_LightGrey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Anyone can join" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_margin="10dp"
android:background="@color/dark_gray" />
<RadioButton
android:id="@+id/network_creation_public"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:drawableRight="@drawable/unlock"
android:text="Public"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
style="@style/TextView_LightGrey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Join via a suggest from existing\nnetwork members" />
</RadioGroup>
答案 0 :(得分:1)
单选按钮选择器xml
res/drawable/radio_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/btn_selected" android:state_checked="true"/>
<item android:drawable="@drawable/btn_unselected" android:state_checked="false"/>
</selector>
现在将 android:background="@drawable/radio_selector"
android:drawableRight="@drawable/radio_selector"
添加到每个单选按钮标记。
答案 1 :(得分:0)