Reputation: 253
I got some problem while changing RadioButton's background property
First of all i want to create Line below each Radio Button which are three in One Radiobutton Group
here is the below code
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="@android:color/black"
android:orientation="vertical" >
<RadioButton
android:id="@+id/radioBtnFirst"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/custom_radiogroup_divider"
android:text="Answer 1"/>
<RadioButton
android:id="@+id/radioBtnTwo"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/custom_radiogroup_divider"
android:text="Answer 2"/>
<RadioButton
android:id="@+id/radioBtnThree"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/custom_radiogroup_divider"
android:text="Answer 3"/>
</RadioGroup>
Now in drawable folder custom_radiogroup_divider.xml is
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@android:color/transparent" />
<stroke
android:width="0.3dp"
android:color="@android:color/black" />
</shape>
but now problem is when i use background property
the radio button will look like text is overlapping the radiobutton
Upvotes: 3
Views: 5031
Reputation: 6738
Do not set drawable to background but set it to button.
Use this
<RadioButton
android:id="@+id/radioBtnFirst"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:button="@drawable/custom_radiogroup_divider"
android:text="Answer 1" />
Upvotes: 2
Reputation: 1865
You have to set your radiobutton's background from Java code:
radioBtnFirst.setButtonDrawable(R.drawable.custom_radiogroup_divider);
It works with checkbox too ;)
Upvotes: 5