A RadioButton
represents a button with two states, selected and unselected.
Unlike checkboxes, changes in the states of one radio button can affect other
buttons in the group. Specifically, selecting a RadioButton
in a RadioGroup
will de-select all other buttons in that group. A radio button is a circle which
fills in with an inset when selected.
The MaterialRadioButton
widget provides a complete implementation of Material
Design's radio button component. It is auto-inflated when using a non-Bridge
Theme.MaterialComponents.* theme which sets the MaterialComponentsViewInflater.
Example code of how to include the widget in your layout:
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkedButton="@+id/first"
android:orientation="vertical">
<RadioButton
android:id="@+id/first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/first_label"/>
<RadioButton
android:id="@+id/second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/second_label"/>
</RadioGroup>
Using a Material Components theme with MaterialRadioButton
will match the
color of RadioButton
views to your theme's palette. If you want to override
this behavior, as you might with a custom drawable, set the
useMaterialThemeColors
parameter to false.
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:useMaterialThemeColors="false"/>
Use radioButtonStyle
for style changes.
<item name="radioButtonStyle">@style/Widget.MaterialComponents.CompoundButton.RadioButton</item>