2017-08-29 70 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

對不起,延遲響應,正在尋找更多的信息。你的答案很好,但是一旦你改變了背景顏色,文本就與禁用的無線電臺不同步。 –