Ich versuche, mit RadioButtons Gender Switcher zu machen. Jetzt sieht es wie this aus.RadioButton mit Vektorzeichen
Ich verwende Vektorzeichen als Symbole. Ich möchte es @color:colorAccent
machen und seinen Hintergrund in einen weißen Kreis ändern, wenn Knopf gedrückt wird. Wie wäre es besser, es zu tun?
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"/>
Ich verwende jetzt einen Selektor (XML ist in der Frage zur Verfügung gestellt), aber es funktioniert nicht, Schaltflächen sehen immer wie deaktiviert aus. –
Sie müssen jetzt 'android: button =" @ drawable/custom_btn_radio "/>' Wenn Sie es so nennen, sollten Sie wahrscheinlich 'male' im Namen erwähnen. – weston
Ich benutze bereits 'android: button =" @ drawable/custom_btn_radio "/>', nur vergessen, den Code in Frage zu aktualisieren, wenn Selektor hinzugefügt –