Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the text color of Radio Button in Android?

Tags:

android

xml

I want to change the text colour of radio button. I have tried but its not change of the text colour.How to change the text colour of radio button.Can some one give me idea how to change the colour . Thanks to appreciate.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/logoKartavya"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:contentDescription="@string/desc"
        android:src="@drawable/logo" />

    <TableLayout
        android:id="@+id/quizLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/logoKartavya" >

        <TextView
            android:id="@+id/questionTopic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:clickable="false"
            android:gravity="center"
            android:textColor="@android:color/black"
            android:textSize="18sp"
            android:textStyle="normal|bold" />

        <EditText
            android:id="@+id/question"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:cursorVisible="false"
            android:editable="false"
            android:lines="3" >

            <requestFocus />
        </EditText>

        <RadioGroup
            android:id="@+id/answers"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp" >

            <RadioButton
                android:id="@+id/a0"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="RadioButton"
                android:textColor="@android:color/black" />

            <RadioButton
                android:id="@+id/a1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="RadioButton"
                android:textColor="@android:color/black" />

            <RadioButton
                android:id="@+id/a2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="RadioButton"
                android:textColor="@android:color/black" />

            <RadioButton
                android:id="@+id/a3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="RadioButton"
                android:textColor="@android:color/black" />
        </RadioGroup>
    </TableLayout>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/Prev"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.21"
            android:text="&lt;&lt;" />

        <Button
            android:id="@+id/finish"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.18"
            android:text="Finish" />

        <Button
            android:id="@+id/Next"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.23"
            android:text=">>" />
    </LinearLayout>

</RelativeLayout>
like image 724
anju patel Avatar asked Dec 25 '22 02:12

anju patel


2 Answers

android:textColor="@color/base_tabpager_indicator_color"

base_tabpager_indicator_color.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_checked="true" android:color="#fffb9749" />
   <item android:color="#ffffffff" />
</selector>
like image 93
Leo Avatar answered Jan 10 '23 03:01

Leo


From your layout, you'll need to set your textColor to a Drawable Selector file.

That file will define the state_checked, state_selected and normal states.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:color="@android:color/black" />
    <item android:state_pressed="true" android:color="@android:color/black" />
    <item android:color="@color/colorPrimary" />
</selector>
<Button
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:textColor="@drawable/txt_segmented"/>
like image 29
Morgan Koh Avatar answered Jan 10 '23 02:01

Morgan Koh