2017-08-29 68 views
0

我想要一些禁用查看文本的单选按钮,但单选按钮看起来很正常。如何启用单选按钮但禁用文本

用户可以单击单选按钮,将显示一些关于未来版本的挑逗,但我也想清楚地展示哪些功能尚未提供。

这里有一个画面:

enter image description here

而且到目前为止我的代码,实际上,我希望有一个更好的解决方案,但如果情况并非如此下面的代码中存在以下问题:

  • 由于测试无线电设备不是无线电组布局它们不会取消选择其他的兄弟姐妹下,

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

  • 看起来写多了一行会换行,但它超出线性布局几个像素。

    <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> 
    

+0

设置文本颜色相同残疾人 –

+0

改变颜色(?) –

+0

@VladMatvienko好主意,但是是所有Android设备上使用相同的颜色吗? –

回答

0

可以使用getCurrentTextColor()得到的颜色,然后用setTextColor(color)的单选按钮

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

enter image description here

使用的文字颜色属性

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

对不起,延迟响应,正在寻找更多的信息。你的答案很好,但是一旦你改变了背景颜色,文本就与禁用的无线电台不同步。 –