单选按钮和文本在设备上不可见。

3

我正在使用Android Studio,我的项目中有一个由4个按钮组成的单选按钮组,用于从我的数据库中选择答案。这些按钮在设备上是不可见的,但当它们被点击时会显示为绿色。此外,每个答案的文本也没有显示,但是单选按钮上方的textview中显示了问题文本!非常令人困惑。是否有人遇到过此问题并知道如何解决?以下是我的xml布局的副本。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:gravity="center_horizontal"
    android:background="@drawable/background">

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:paddingTop="15dip" 
        android:paddingBottom="15dip"
        android:gravity="center_horizontal">

        <ImageView android:id="@+id/logo" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:src="@drawable/logo2" />

    </LinearLayout>

    <LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dip"
        android:paddingBottom="5dip"
        android:gravity="center_horizontal">

        <RadioGroup android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:orientation="vertical"
            android:id="@+id/group1">

            <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:textColor="#ffffff"
                android:textStyle="bold" 
                android:id="@+id/question"/>

            <RadioButton android:checked="false" android:id="@+id/answer1"
                />

            <RadioButton android:checked="false" android:id="@+id/answer2"
                />

            <RadioButton android:checked="false" android:id="@+id/answer3"
                />

            <RadioButton android:checked="false" android:id="@+id/answer4"
                />

        </RadioGroup>

    </LinearLayout>


    <Button android:text="Next"
        android:id="@+id/nextBtn"
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_height="wrap_content"
        android:background="@drawable/button_selector"
        android:paddingTop="5dip"
        android:paddingBottom="5dip"
        android:textColor="#ffffff"
        android:layout_gravity="center_horizontal" />

</LinearLayout>


我找不到你在哪里改变了单选按钮的文本颜色。你把TextView的文本颜色改成了白色...可能你有一个黑色背景上面有黑色文本和黑色图标吗? - AlbAtNf
尝试更改主视图的背景,可能与文本和单选按钮的背景颜色相同。这就是为什么它们在你看来看起来是透明的原因。 - Rami
我尝试过更改背景,文本是白色的,背景是黑色的,在TextView上方显示的文本没有问题,但是RadioGroup是看不见的。 - james
刚刚尝试了一下,问题还是一样的。 - james
你的运行代码片段按钮是做什么用的?它什么都不显示。 - IgorGanapolsky
1个回答

2

只需将单选按钮组的单选按钮替换为以下内容:

<RadioButton android:checked="false" android:id="@+id/answer1"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="text 1"
            />

        <RadioButton android:checked="false" android:id="@+id/answer2"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="text 2"
            />

        <RadioButton android:checked="false" android:id="@+id/answer3"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="text 3"
            />

        <RadioButton android:checked="false" android:id="@+id/answer4"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="text 4"
            />

它将工作:)


很遗憾,同样的问题:-( 这真是个难题,单选按钮组应该显示来自我的数据库的答案,它们最初确实显示出来了,我想这不可能是数据库的问题,因为问题显示得很好!只是单选按钮组和答案都不可见。 - james
在你对每个按钮进行编辑后,更改了文本颜色,并且现在答案正在显示,但是单选按钮不可见。 - james
所以,单选按钮组内的圆点没有正确显示吗? - Hardik Chauhan
如果有帮助的话,这是一个选择检查按钮。 - james
嗨,我已经添加了相同的布局,包括静态文本和背景。 而且它一直都很正常,我可以看到问题、答案和所有的单选按钮。你是在以编程方式进行任何设计更改吗? - Hardik Chauhan
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接