Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使单选按钮处于启用状态,但文本看起来处于禁用状态_Android - Fatal编程技术网

Android 如何使单选按钮处于启用状态,但文本看起来处于禁用状态

Android 如何使单选按钮处于启用状态,但文本看起来处于禁用状态,android,Android,我想要一些单选按钮,已禁用查看文本,但单选按钮看起来正常 用户可以单击单选按钮,并将显示一些关于未来版本的提示,但我还想清楚地显示哪些功能尚不可用 这是一张照片: 到目前为止,我的代码,实际上我希望有一个更好的解决方案,但如果不是这样,下面的代码有以下问题: 由于测试无线电不在无线电组布局下,因此它们不会取消选中其他同级 因为测试实际上是两个收音机(一个是按钮而不是文本,另一个是文本而不是按钮),点击文本不会检查按钮!这其实很重要 似乎写多行会换行,但会超出线性布局几个像素 <Radi

我想要一些单选按钮,已禁用查看文本,但单选按钮看起来正常

用户可以单击单选按钮,并将显示一些关于未来版本的提示,但我还想清楚地显示哪些功能尚不可用

这是一张照片:

到目前为止,我的代码,实际上我希望有一个更好的解决方案,但如果不是这样,下面的代码有以下问题:

  • 由于测试无线电不在无线电组布局下,因此它们不会取消选中其他同级

  • 因为测试实际上是两个收音机(一个是按钮而不是文本,另一个是文本而不是按钮),点击文本不会检查按钮!这其实很重要

  • 似乎写多行会换行,但会超出线性布局几个像素

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Normal, unchecked" />
    
        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Normal, unchecked" />
    
        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Normal, checked" />
    
        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:enabled="false"
            android:text="Disabled, unchecked" />
    
        <RadioButton
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:checked="true"
            android:enabled="false"
            android:text="Disabled, checked, also big line saijdhnasoidasokdmokasmdokasmdkmasdplmaslk;dmsal;kdmas;lmdl;asmdl;mas;ldmasl;dmaslkmdksamdasmdlka" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
    
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:enabled="false"
                android:text="Test, unchecked, also big line saijdhnasoidasokdmokasmdokasmdkmasdplmaslk;dmsal;kdmas;lmdl;asmdl;mas;ldmasl;dmaslkmdksamdasmdlka" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true" />
    
            <RadioButton
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:enabled="false"
                android:text="Test, checked" />
        </LinearLayout>
    
    </RadioGroup>
    

    
    

使用textcolor属性

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="test"
        android:textColor="#AAA"/>

您可以使用
getCurrentTextColor()
获取颜色,然后使用单选按钮上的
setTextColor(颜色)

    RadioButton checkbox=(RadioButton) getView().findViewById(R.id.first);
    checkbox.setEnabled(false);
    int color=checkbox.getCurrentTextColor();
    checkbox.setEnabled(true);
    checkbox.setTextColor(color);

将文本颜色设置为与disabledchange相同颜色(?)@VladMatvienko是个好主意,但所有android设备上都使用相同的颜色吗?不,但您可以定义主题,该主题将应用于所有设备。对于延迟响应,Orry正在搜索更多信息。你的答案是好的,但是一旦你改变了背景颜色,文本就会与禁用的RadioBox不同步。