SplitButton is a re-creation of the Material3 Split Button, inspired by the Material Components Android Button documentation. This library provides a highly customizable implementation of the Material3 Split Button, which is currently not included in the stable Material library.
- Fully customizable split button.
- Supports dynamic addition and removal of buttons.
- Implements Material Design principles.
- Easy to integrate into any Android project.
- Built-in fade-in and fade-out animations for adding and removing buttons dynamically.
-
Clone the repository to your local machine:
git clone https://github.com/Siddhesh2377/MaterialSplitButton-ReCreated.git
-
Copy the
splitBtn
library module into your Android Studio project.
-
In your
settings.gradle
file, include thesplitBtn
module:include(":splitBtn") project(":splitBtn").projectDir = file("path-to-splitBtn-module")
-
In your app module's
build.gradle
file, add the library as a dependency:dependencies { implementation project(":splitBtn") }
Include the SplitButton in your layout XML:
<com.dark.splitbtn.SplitButton
android:id="@+id/splitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:childBackgroundColor="@color/primary"
app:childTextColor="@color/onPrimary"
app:edgeCorner="16dp"
app:childCorner="8dp"
app:childSpacing="8dp">
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First" />
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Middle" />
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last" />
</com.dark.splitbtn.SplitButton>
You can add or remove buttons dynamically:
val splitButton = findViewById<SplitButton>(R.id.splitButton)
splitButton.addNewButton("New Button")
splitButton.removeViewAt(1) // Removes the button at index 1
Attribute | Format | Description |
---|---|---|
childBackgroundColor |
color |
Background color of the child buttons. |
childTextColor |
color |
Text color of the child buttons. |
edgeCorner |
float |
Corner radius for the first and last buttons. |
childCorner |
float |
Corner radius for the middle buttons. |
childSpacing |
dimension |
Spacing between the child buttons. |
Contributions are welcome! If you find any issues or want to improve this library, feel free to open a pull request or issue on GitHub.
This project is licensed under the MIT License. See the LICENSE file for more details.
This library is inspired by the Material Components Android Split Button and aims to bring a similar experience to stable Material3 implementations.