MaterialSplitButton


public class MaterialSplitButton extends MaterialButtonGroup


A container for two MaterialButtons that together create a split button. The MaterialButtons in this group will be shown on a single line.

This layout currently only supports child views of type MaterialButton. Buttons can be added to this view group via XML, as follows:

<com.google.android.material.button.MaterialSplitButton
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/split_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/split_button_label"
        app:icon="@drawable/ic_edit_vd_theme_24dp"
        app:iconGravity="start"/>
    <Button
       style="?attr/materialSplitButtonIconFilledStyle"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:contentDescription="@string/split_button_label_chevron"
       app:icon="@drawable/m3_split_button_chevron_avd"/>

</com.google.android.material.button.MaterialSplitButton>

Buttons can also be added to this view group programmatically via the addView methods.

MaterialSplitButton is a MaterialButtonGroup with only two MaterialButtons.

For more information, see the component developer guidance and design guidelines.

Summary

Public constructors

MaterialSplitButton(Context context)
MaterialSplitButton(Context context, AttributeSet attrs)
MaterialSplitButton(
    Context context,
    AttributeSet attrs,
    int defStyleAttr
)

Public methods

void
addView(View child, int index, LayoutParams params)

This override prohibits Views other than MaterialButton to be added where the leading MaterialButton has either an icon and/or a label and the trailing MaterialButton has an animated vector drawable as an icon.

Inherited Constants

From com.google.android.material.button.MaterialButtonGroup
static final Object
static final int

A value for overflowMode.

static final int

A value for overflowMode.

static final int

A value for overflowMode.

Inherited methods

From com.google.android.material.button.MaterialButtonGroup
boolean
checkLayoutParams(LayoutParams p)
void
dispatchDraw(Canvas canvas)
MaterialButtonGroup.LayoutParams
MaterialButtonGroup.LayoutParams
generateLayoutParams(AttributeSet attrs)
MaterialButtonGroup.LayoutParams
generateLayoutParams(LayoutParams p)
int
getChildDrawingOrder(int childCount, int i)

We keep track of which views are pressed and checked to draw them last.

ShapeAppearanceModel

Returns the original ShapeAppearanceModel for the MaterialButton child at the given index.

CornerSize

Returns the inner corner size of the group.

Drawable

Returns the icon shown for the overflow button, if present.

int

Returns the overflow mode.

ShapeAppearanceModel

Returns the ShapeAppearanceModel of the group.

int

Returns the spacing (in pixels) between each button in the group.

void
onLayout(boolean changed, int l, int t, int r, int b)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void
onViewRemoved(View child)
void
setEnabled(boolean enabled)

Enables this MaterialButtonGroup and all its MaterialButton children

void

Sets the inner corner size of the group.

void
setOrientation(int orientation)
void
setOverflowButtonIcon(Drawable icon)

Sets the icon to show for the overflow button.

void
setOverflowButtonIconResource(int iconResourceId)

Sets the icon to show for the overflow button.

void
setOverflowMode(int overflowMode)

Sets the overflow mode.

void

Sets the ShapeAppearanceModel of the group.

void
setSpacing(int spacing)

Sets the spacing between each button in the group.

Public constructors

MaterialSplitButton

public MaterialSplitButton(Context context)

MaterialSplitButton

public MaterialSplitButton(Context context, AttributeSet attrs)

MaterialSplitButton

public MaterialSplitButton(
    Context context,
    AttributeSet attrs,
    int defStyleAttr
)

Public methods

addView

public void addView(View child, int index, LayoutParams params)

This override prohibits Views other than MaterialButton to be added where the leading MaterialButton has either an icon and/or a label and the trailing MaterialButton has an animated vector drawable as an icon. It also makes updates to the add button shape and margins.