2017-09-04 24 views
0

私のアプリでradioButtonを使用していますが、デフォルトではradioButtonの色は黒で、それを選択するとcolor.xmlに記載されている色のアクセントの色に変わりますradioButton初期色を選択し、選択した色を白色に変更します。どのように私はそうすることができます。背景色を試しましたが、背景色のプロパティが変わります。助けてください。androidのラジオボタンの円の色を変更できません

+0

デフォルトでレイアウトXMLでラジオボタンのスタイルを変更し、選択した色、スタイルから取得し、それがcolorAscent ..です新しいスタイルを試してみて、それを追加あなたのラジオボタンに –

+4

[ラジオボタンの色を変更する](https://stackoverflow.com/questions/18696275/change-color-of-a-radio-button) –

+0

@VishalThakkarの複製がありません –

答えて

0

まず

<!-- custom style --> 
<style name="radionbutton" 
     parent="Base.Widget.AppCompat.CompoundButton.RadioButton"> 
    <item name="android:button">@drawable/rb_drawable</item> 
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:windowBackground">@android:color/transparent</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowIsFloating">false</item> 
    <item name="android:backgroundDimEnabled">true</item> 
</style> 

今すぐ/

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

今ラジオボタン、チェックのための2つの以上のファイルを作る描画可能なフォルダにrb_drawable.xmlを作る描画可能なフォルダにチェックを外しstyle.xmlにこのコードを入れて

radio_unchecked.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval"> 
    <stroke android:width="1dp" android:color="@color/colorAccent"/> 
    <size android:width="30dp" android:height="30dp"/> 
</shape> 

radio_checked.xml

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
    <shape android:shape="oval"> 
     <stroke android:width="1dp" android:color="@color/colorAccent"/> 
     <size android:width="30dp" android:height="30dp"/> 
    </shape> 
    </item> 
    <item android:top="5dp" android:bottom="5dp" android:left="5dp" android:right="5dp"> 
    <shape android:shape="oval"> 
     <solid android:width="1dp" android:color="@color/colorAccent"/> 
     <size android:width="10dp" android:height="10dp"/> 
    </shape> 
    </item> 
</layer-list> 

が最後に

<RadioButton 
    android:layout_width="wrap_content" 
    style="@style/radionbutton" 
    android:checked="false" 
    android:layout_height="wrap_content" 
    /> 
関連する問題