J'essaie de faire un changement de genre en utilisant RadioButtons. Maintenant, il ressemble à this. J'utilise des dessins vectoriels comme icônes. Je veux faire @color:colorAccent
et changer son arrière-plan en cercle blanc, lorsque le bouton est pressé. Comment serait-il préférable de le faire?RadioButton avec des tirables vectoriels
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"/>
J'utilise un sélecteur maintenant (le XML est fourni dans la question), mais ça ne marche pas, les boutons ont toujours l'air de ne pas être cochés. –
Vous devez maintenant utiliser 'android: button =" @ drawable/custom_btn_radio "/>' Si c'est ce que vous appelez, vous devriez probablement mentionner 'male' dans le nom. – weston
J'utilise déjà 'android: button =" @ drawable/custom_btn_radio "/>', juste oublié de mettre à jour le code en question lors de l'ajout du sélecteur –