ToggleButtonLayout
Easy creation and management of toggle buttons from the Material Design spec.
Dependency
Add this in your root build.gradle
file (not your module build.gradle
file):
Then, add the library to your project build.gradle
Usage
Add the ToggleButtonLayout to your layout:
where the toggles menu looks like:
You can safely ignore lint warnings about needing a title on each item, unless you want a title to appear on each item.
Later, you can get the selected items via:
And you can listen for when toggles are switched:
Customization
You can customize the ToggleButtonLayout
via XML attributes:
If you use the customLayout
attribute, the layout is expected to have a TextView
with an ID of android:id="@android:id/text1"
if you are using a title, and if you are using an icon, android:id="@android:id/icon"
. You can omit either of these if you are only using a menu resource with a title or just an icon. See the sample for more.
Notes
- If you need to rely on a Java version of
ToggleButtonLayout
, you can use thejava
branch. - Please open an issue or make a pull request for additional features you might want. For PRs, please follow the Android Kotlin Style Guide