Material Button Toggle Group is a customizable button component with updated visual styles. It groups MaterialButton components.
For more information, go to the material.io Buttons page.
MaterialButtonToggleGroup, sometimes referred to as Toggle Button, Toggle Button Group, or Segmented Selector, is a ViewGroup that groups together
several checkable MaterialButton child views. The buttons in this
group will be shown on a single line.
Go to the Android MaterialButtonToggleGroup API for more details.
Note We recommend that child buttons use an outlined style. For more information on button styling, see MaterialButton
<com.google.android.material.button.MaterialButtonToggleGroup
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toggle_button_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_label_private"/>
/*...*/
<com.google.android.material.button.MaterialButton
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_label_custom"/>
</com.google.android.material.button.MaterialButtonToggleGroup>| Attribute | Description | Possible values |
|---|---|---|
android:id |
"@+id/toggle_button_group" |
|
android:layout_width |
"wrap_content" |
|
android:layout_height |
"wrap_content" |
|
android:enabled |
true|false |
|
style |
"@style/Widget.MaterialComponents.Button.UnelevatedButton" "@style/Widget.MaterialComponents.Button.TextButton" |
| Method | Description |
|---|---|
addView(View) |
Programmatically adds buttons to the toggle group |
OnButtonCheckedListener |
Listens for changes to the child buttons' checked state |
addOnButtonCheckedListener |
Adds a listener to check the state of child buttons |
removeOnButtonCheckedListener |
Removes listener that checks the sate of child buttons |
The following example shows a toggle group with outlined buttons.
\* example code here *\\* example code here *\