Question

I have a form like this :

Image

With the code :

<RadioGroup
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="570dp"
    android:layout_marginTop="160dp" >

        <RadioButton
            android:id="@+id/button_service"
            style="@style/type_action"
            android:text="@string/service" />

        <RadioButton
            android:id="@+id/button_reception"
            style="@style/type_action"
            android:layout_alignLeft="@id/button_service"
            android:layout_alignTop="@id/button_service"
            android:layout_marginTop="10dp"
            android:text="@string/defense" />

        <RadioButton
            android:id="@+id/button_passe"
            style="@style/type_action"
            android:layout_alignLeft="@id/button_service"
            android:layout_alignTop="@id/button_reception"
            android:layout_marginTop="10dp"
            android:text="@string/passe" />

         <RadioButton
            android:id="@+id/button_attaque"
            style="@style/type_action"
            android:layout_alignLeft="@id/button_service"
            android:layout_alignTop="@id/button_passe"
            android:layout_marginTop="10dp"
            android:text="@string/attaque" />

         <RadioButton
            android:id="@+id/button_bloc"
            style="@style/type_action"
            android:layout_alignLeft="@id/button_service"
            android:layout_alignTop="@id/button_attaque"
            android:layout_marginTop="10dp"
            android:text="@string/bloc" />

         <RadioButton
            android:id="@+id/button_faute"
            style="@style/type_action"
            android:layout_alignLeft="@id/button_service"
            android:layout_alignTop="@id/button_bloc"
            android:layout_marginTop="10dp"
            android:text="@string/faute" />
</RadioGroup>

And style.xml

<style name="type_action">
    <item name="android:textSize">30sp</item>
    <item name="android:textColor">#EEEEEE</item>
    <item name="android:background">#000000</item>
    <item name="android:textStyle">bold</item>
    <item name="android:layout_width">200dp</item>
    <item name="android:layout_height">50dp</item>
    <item name="android:gravity">center</item>      
</style>

I want to remove the default icons that are on my buttons. And I wish instead of that, when a button is checked, it's is highlighted in becoming yellow for example.

How can I do that ?

Thanks for the help (and sorry for my bad english).

Was it helpful?

Solution

And I wish instead of that, when a button is checked, it's is highlighted in becoming yellow for example.

You can define your own radiobutton_selector.xml for radio button:

<?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_checked="true" android:drawable="@drawable/unchecked" />
        <item android:state_checked="false" android:drawable="@drawable/checked" />
    </selector>

and then set it to RadioButton like

<RadioButton
            android:id="@+id/button_faute"
            android:button="@drawable/radiobutton_selector"
            style="@style/type_action"
            android:layout_alignLeft="@id/button_service"
            android:layout_alignTop="@id/button_bloc"
            android:layout_marginTop="10dp"
            android:text="@string/faute" />

//EDIT

also i found this tutorial or tutorial1 with full source code for customizing radio buttons in way you as you want to :P

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top