2013-03-29 32 views
1

我在android中有一個自定義單選按鈕。 它的工作很好。我的問題是,當我禁用這些按鈕時,它不會變灰。我該怎麼做?這是我的自定義單選按鈕的示例代碼。Android應用中的自定義單選按鈕在禁用時不會灰顯

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_checked="true" android:drawable="@drawable/radio_select" /> 
<item android:state_checked="false" android:drawable="@drawable/radio_holo" /> 
</selector> 

下面是代碼,我在我的佈局中使用

,我需要的文本外觀小巧和普通文本的顏色黑色
<RadioButton 
    android:id="@+id/radioButton2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:button="@drawable/custom_radio_button" 
    android:onClick="OnClick" 
    android:text="button 1" 
    android:textAppearance="?android:attr/textAppearanceSmall" 
    android:textColor="@color/black" /> 

一件事。

回答

0

嘗試添加以下內容到custom_radio_button.xml:

<item android:state_enabled="false" android:drawable="@drawable/your_grayed_out_btn" /> 
+0

我需要變灰的文字不是按鈕。 –

0

如果您需要根據您的RadioButton的狀態來改變文字顏色,嘗試如圖this答案寫一個選擇。