I am wanting to allow the user of my android application the ability to set some parameters. The radio button is ideal for this situation. However, I don't like the radio buttons are rendered.
Is it possible to change the radio button icon? For example, is it possible to create a custom layout for each row and in that layout reference my own icon and change the font et al.
In Android, RadioButton are mainly used together in a RadioGroup. In RadioGroup checking the one radio button out of several radio button added in it will automatically unchecked all the others. It means at one time we can checked only one radio button from a group of radio buttons which belong to same radio group.
Just use the android:buttonTint="@color/colorPrimary" attribute on the <RadioButton> tag. Show activity on this post. to the colour you want.
List<String> list = new ArrayList<String>(); list. add("one"); list. add("two"); list. add("three"); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.
To create each radio button option, create a RadioButton in your layout. However, because radio buttons are mutually exclusive, you must group them together inside a RadioGroup . By grouping them together, the system ensures that only one radio button can be selected at a time.
Yes that's possible you have to define your own style for radio buttons, at res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="CustomTheme" parent="android:Theme"> <item name="android:radioButtonStyle">@style/RadioButton</item> </style> <style name="RadioButton" parent="@android:style/Widget.CompoundButton.RadioButton"> <item name="android:button">@drawable/radio</item> </style> </resources>
'radio' here should be a stateful drawable, radio.xml:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:state_window_focused="false" android:drawable="@drawable/radio_hover" /> <item android:state_checked="false" android:state_window_focused="false" android:drawable="@drawable/radio_normal" /> <item android:state_checked="true" android:state_pressed="true" android:drawable="@drawable/radio_active" /> <item android:state_checked="false" android:state_pressed="true" android:drawable="@drawable/radio_active" /> <item android:state_checked="true" android:state_focused="true" android:drawable="@drawable/radio_hover" /> <item android:state_checked="false" android:state_focused="true" android:drawable="@drawable/radio_normal_off" /> <item android:state_checked="false" android:drawable="@drawable/radio_normal" /> <item android:state_checked="true" android:drawable="@drawable/radio_hover" /> </selector>
Then just apply the Custom theme either to whole app or to activities of your choice.
For more info about themes and styles look at http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/ that is good guide.
You can put custom image in radiobutton like normal button. for that create one XML file in drawable folder e.g
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/sub_screens_aus_hl" android:state_pressed="true"/> <item android:drawable="@drawable/sub_screens_aus" android:state_checked="true"/> <item android:drawable="@drawable/sub_screens_aus" android:state_focused="true" /> <item android:drawable="@drawable/sub_screens_aus_dis" /> </selector>
Here you can use 3 different images for radiobutton
and use this file to RadioButton like:
android:button="@drawable/aus" android:layout_height="120dp" android:layout_width="wrap_content"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With