1
나는 RadioButton을 사용하여 젠더 스위처를 만들려고합니다. 이제 this처럼 보입니다.벡터 드로어 블을 포함한 RadioButton
저는 벡터 드로어 블을 아이콘으로 사용합니다. 나는 그것을 @color:colorAccent
으로 만들고 단추를 누를 때 배경을 흰색 원으로 변경하려고합니다. 어떻게하는 것이 좋을까요?
layout.xml
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton"
android:background="?attr/selectableItemBackgroundBorderless"
android:layout_weight="1"
android:layout_marginEnd="8dp"
android:button="@drawable/custom_btn_radio"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioButton2"
android:background="?attr/selectableItemBackgroundBorderless"
android:layout_weight="1"
android:layout_marginStart="8dp"
android:button="@drawable/custom_btn_radio"/>
</LinearLayout>
</RadioGroup>
custom_btn_radio.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false"
android:drawable="@drawable/human_male"/>
<item android:state_checked="true"
android:drawable="@drawable/human_male"
android:background="@android:color/white"
android:tint="@color/colorAccent"/>
지금 선택기를 사용하고 있습니다 (질문에 XML이 제공됨).하지만 작동하지 않습니다. 단추는 항상 선택 취소 된 것처럼 보입니다. –
이제'android : button = "@ drawable/custom_btn_radio"/>를 사용해야합니다. 이름을 'male'이라고 써야합니다. – weston
나는 이미'android : button = "@ drawable/custom_btn_radio"/>'을 사용하고 있는데, 셀렉터가 추가되었을 때 해당 코드를 업데이트하는 것을 잊어 버렸습니다. –