android - How to set the background colour of a RadioButton? -


can please tell me how set background colour of radiobutton?
if user selects yes, background color should change green.
when user selects no, background color should change red.

here xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >      <include layout="@layout/header" />      <tablelayout         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:paddingtop="20dp"         android:stretchcolumns="2" >          <tablerow android:layout_width="match_parent"             android:layout_height="wrap_content"             android:background="#ffff00" >              <textview                 android:layout_height="wrap_content"             android:layout_width="0dp"                 android:padding="5dp"                 android:text="eligibility confirmed:"                  android:layout_weight=".5"/>              <radiogroup                 android:id="@+id/eligibility"                 android:layout_height="wrap_content"                 android:layout_width="0dp"                 android:orientation="horizontal"                 android:layout_weight=".5" >                  <radiobutton                     android:id="@+id/eligibilityyes"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:checked="true"                     android:text="yes" />                  <radiobutton                     android:id="@+id/eligibilityno"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:text="no" />             </radiogroup>         </tablerow>          <tablerow             android:focusable="true"             android:focusableintouchmode="true"             android:background="#ffff00" >              <textview                 android:layout_width="0dp"                 android:layout_height="wrap_content"                 android:padding="5dp"                 android:text="informed consent given , explained:"               android:layout_weight=".5"                />              <radiogroup                 android:id="@+id/explained"                 android:layout_width="0dp"                 android:layout_height="wrap_content"                 android:orientation="horizontal"                  android:layout_weight=".5">                  <radiobutton                     android:id="@+id/explainedyes"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:checked="true"                     android:text="yes" />                  <radiobutton                     android:id="@+id/explainedno"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:text="no" />             </radiogroup>         </tablerow>     </tablelayout>     <!--          <button                  android:layout_height="wrap_content"                 android:layout_width="wrap_content"                 android:text="clickme"/>     --> </linearlayout> 

you should try way.. hope you....

<radiogroup             android:id="@+id/eligibility"             android:layout_height="wrap_content"             android:layout_width="0dp"             android:orientation="horizontal"             android:layout_weight=".5" >              <radiobutton                 android:id="@+id/eligibilityyes"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:checked="true"                 android:background="@drawable/checkbox_background"                 android:text="yes" />              <radiobutton                 android:id="@+id/eligibilityno"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:background="@drawable/checkbox_background"                 android:text="no" />         </radiogroup> 

your checkbox_background.xml file put image in res/drawable

<?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/radio_rad" />     <item android:state_checked="true" android:drawable="@drawable/radio_green" />  </selector> 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -