如何在Android中更改单选按钮的文本颜色?

时间:2022-04-05 09:44:34

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>

3 个解决方案

#1


1  

Just put the hedxadecimal code of color in

只需将颜色的hedxadecimal代码放入

android:textColor="#0000000"

#2


4  

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>

#3


1  

simple, just add

简单,只需添加

android:hint="your text"
android:textColorHint="YourColor"

instead of text and androidTextColor

而不是文本和androidTextColor

#1


1  

Just put the hedxadecimal code of color in

只需将颜色的hedxadecimal代码放入

android:textColor="#0000000"

#2


4  

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>

#3


1  

simple, just add

简单,只需添加

android:hint="your text"
android:textColorHint="YourColor"

instead of text and androidTextColor

而不是文本和androidTextColor