ToggleButtonLayout

by savvyapps

Easy creation and management of toggle buttons on Android from the Material Design spec.

218 Stars 27 Forks Last release: over 1 year ago (1.3.0) Apache License 2.0 19 Commits 4 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

ToggleButtonLayout

Easy creation and management of toggle buttons from the Material Design spec. Read more about ToggleButtonLayout in our blog post.

Single Multiple Segmented

Build Status

Dependency

Add this in your root

build.gradle
file (not your module
build.gradle
file):
allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Then, add the library to your project

build.gradle
gradle
dependencies {
    implementation 'com.github.savvyapps:ToggleButtonLayout:latest.version.here'
}

Usage

Add the ToggleButtonLayout to your layout:

xml

where the toggles menu looks like: ```xml <?xml version="1.0" encoding="utf-8"?>

``` 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:

kotlin
val selectedToggles = toggleButtonLayout.selectedToggles()
//do what you need to with these selected toggles
And you can listen for when toggles are switched:
kotlin
toggleButtonLayout.onToggledListener = { toggle, selected ->
    Snackbar.make(root, "Toggle " + toggle.id + " selected state " + selected, Snackbar.LENGTH_LONG)
            .show()
}

Customization

You can customize the

ToggleButtonLayout
via XML attributes:
xml

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 the
    java
    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

License

Copyright 2019 Savvy Apps

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.