Skip to content

Commit 9f801b8

Browse files
kendrickumstattddrchen
authored andcommitted
[Button] Add documentation about SplitButton
PiperOrigin-RevId: 691831836
1 parent 3bb2df8 commit 9f801b8

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

docs/components/Button.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,81 @@ Element | Style | Theme Attribute
748748
----------------- | -------------------------------------- | ---------------
749749
**Default style** | `Widget.Material3.MaterialButtonGroup` | `?attr/materialButtonGroupStyle`
750750

751+
### Split button
752+
753+
A specialized type of the connected button group is the split button. The
754+
trailing button is checkable with an animated icon.
755+
756+
![Examples of using split button](assets/buttons/split_button.png)
757+
758+
#### Split button examples
759+
760+
Source code:
761+
762+
* `MaterialSplitButton`
763+
* [Class source](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/button/MaterialSplitButton.java)
764+
765+
The following example shows a split button with a leading label button and a
766+
trailing icon button that has an AnimatedVectorDrawable.
767+
768+
In the layout:
769+
770+
```xml
771+
<com.google.android.material.button.MaterialSplitButton
772+
xmlns:android="http://schemas.android.com/apk/res/android"
773+
xmlns:app="http://schemas.android.com/apk/res-auto"
774+
android:id="@+id/splitbutton"
775+
android:layout_width="wrap_content"
776+
android:layout_height="wrap_content">
777+
<Button
778+
android:layout_width="wrap_content"
779+
android:layout_height="wrap_content"
780+
android:text="@string/split_button_label"
781+
app:icon="@drawable/ic_edit_vd_theme_24dp"/>
782+
<Button
783+
style="?attr/materialSplitButtonIconFilledStyle"
784+
android:id="@+id/expand_more_or_less"
785+
android:layout_height="wrap_content"
786+
android:layout_width="wrap_content"
787+
android:minWidth="48dp"
788+
android:gravity="center"
789+
android:contentDescription="@string/split_button_label_chevron"
790+
app:icon="@drawable/m3_split_button_chevron_avd"/>
791+
</com.google.android.material.button.MaterialSplitButton>
792+
```
793+
794+
### Animated Trailing Icon
795+
796+
The icon on the trailing button is animated. In the samples, this is done with
797+
an AVD, `m3_split_button_chevron_avd`
798+
[[source](https://github.com/material-components/material-components-android/tree/master/lib/java/com/google/android/material/button/res/drawable/m3_split_button_chevron_avd.xml)].
799+
800+
### Properties
801+
802+
Element | Attribute | Related method(s) | Default value
803+
--------------------------- | ---------------------- | --------------------------------------------- | -------------
804+
**Size of inner corners** | `app:innerCornerSize` | `setInnerCornerSize`<br/>`getInnerCornerSize` | `none`
805+
**Spacing between buttons** | `android:spacing` | `setSpacing`<br/>`getSpacing` | `2dp`
806+
**Button size change** | `app:buttonSizeChange` | N/A | `0%`
807+
808+
#### Styles and Theme attributes
809+
810+
Element | Style | Theme Attribute
811+
----------------------------------------- | ------------------------------------------------------------ | ---------------
812+
**Default style** | `Widget.Material3.MaterialSplitButton` | `?attr/materialSplitButtonStyle`
813+
**Trailing icon primary (filled) style** | `Widget.Material3.SplitButton.IconButton.Filled` | `?attr/materialSplitButtonIconFilledStyle`
814+
**Trailing icon secondary (tonal) style** | `Widget.Material3.SplitButton.IconButton.Filled.Tonal` | `?attr/materialSplitButtonIconFilledTonalStyle`
815+
816+
The two new trailing icon styles `materialSplitButtonIconFilledStyle` – parented
817+
by `materialIconButtonFilledStyle` – and
818+
`materialSplitButtonIconFilledTonalStyle`-- parented by
819+
`materialIconButtonFilledTonalStyle` allow for the `MaterialSplitButton` custom
820+
behavior for `onChecked` and `onUnchecked` states.
821+
`materialSplitButtonIconFilledStyle` is paired with default leading button
822+
styling, with no style explicitly specified in the XML.
823+
`materialSplitButtonIconFilledTonalStyle` is paired with
824+
`materialButtonTonalStyle` for the leading button.
825+
751826
## Toggle button groups
752827

753828
[Toggle button group (Segmented buttons)](https://m3.material.io/components/segmented-buttons)
33.6 KB
Loading

0 commit comments

Comments
 (0)