All Projects → savvyapps → Togglebuttonlayout

savvyapps / Togglebuttonlayout

Licence: apache-2.0
Easy creation and management of toggle buttons on Android from the Material Design spec.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Togglebuttonlayout

Listenermusicplayer
A Grace Material Design Music Player
Stars: ✭ 2,360 (+948.89%)
Mutual labels:  material-design
Neteasecloudwebapp
This is a vue for NeteaseCloud projects!
Stars: ✭ 2,456 (+991.56%)
Mutual labels:  material-design
Customfloatingactionbutton
This view is for replacement of standard Floating Action Button from Google Support Library. It is easy to use, customizable and you can also add text to button
Stars: ✭ 222 (-1.33%)
Mutual labels:  material-design
Materialize Blog
redesign blog using material design
Stars: ✭ 212 (-5.78%)
Mutual labels:  material-design
Awesome Wanandroid
⚡致力于打造一款极致体验的 http://www.wanandroid.com/ 客户端,知识和美是可以并存的哦QAQn(*≧▽≦*)n
Stars: ✭ 2,525 (+1022.22%)
Mutual labels:  material-design
Bottomsheet
BottomSheet dialog library for Android
Stars: ✭ 219 (-2.67%)
Mutual labels:  material-design
Flutter speed dial
Flutter plugin to implement a Material Design Speed Dial
Stars: ✭ 206 (-8.44%)
Mutual labels:  material-design
Wanandroid
WanAndroid客户端,项目基于 Material Design + MVP +dagger2 + RxJava + Retrofit + Glide + greendao 等架构进行设计实现,极力打造一款 优秀的玩Android https://www.wanandroid.com 客户端,是一个不错的Android应用开发学习参考项目
Stars: ✭ 223 (-0.89%)
Mutual labels:  material-design
Yoshino
A themable React component library!Flexible Lightweight PC UI Components built on React! Anyone can generate easily all kinds of themes by it!
Stars: ✭ 216 (-4%)
Mutual labels:  material-design
Material Backdrop
A simple solution for implementing Backdrop pattern for Android
Stars: ✭ 221 (-1.78%)
Mutual labels:  material-design
Matblazor
Material Design components for Blazor and Razor Components
Stars: ✭ 2,599 (+1055.11%)
Mutual labels:  material-design
Carbon Ui
React Native Material Design library for all platforms
Stars: ✭ 215 (-4.44%)
Mutual labels:  material-design
Material Admin
Free Material Admin Template
Stars: ✭ 219 (-2.67%)
Mutual labels:  material-design
Twidere Android
twidere.com
Stars: ✭ 2,486 (+1004.89%)
Mutual labels:  material-design
Angular Ngrx Material Starter
Angular, NgRx, Angular CLI & Angular Material Starter Project
Stars: ✭ 2,623 (+1065.78%)
Mutual labels:  material-design
Hubuntu Ui
Material Admin Dashboard Starter UI ( Ubuntu style ) - https://720kb.github.io/hubuntu-ui/
Stars: ✭ 207 (-8%)
Mutual labels:  material-design
Dynamic Support
A complete library to build Android apps with a built-in theme engine.
Stars: ✭ 218 (-3.11%)
Mutual labels:  material-design
Numberslidingpicker
Android Number Picker with gestures
Stars: ✭ 225 (+0%)
Mutual labels:  material-design
Prismatic Night
A dark themed startpage and dark themes for Firefox and Linux inspired by Material design and Adapta.
Stars: ✭ 223 (-0.89%)
Mutual labels:  material-design
Fancywalkthrough Android
Fancy Walkthrough is a simple and lightweight library that helps you to create cool and beautiful introduction screens for your apps without writing dozens of lines of code.
Stars: ✭ 218 (-3.11%)
Mutual labels:  material-design

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

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

Usage

Add the ToggleButtonLayout to your layout:

<com.savvyapps.togglebuttonlayout.ToggleButtonLayout
    android:id="@+id/toggle_button_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginBottom="16dp"
    app:menu="@menu/toggles" />

where the toggles menu looks like:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/toggle_left"
        android:icon="@drawable/ic_format_align_left_black_24dp" />

    <item
        android:id="@+id/toggle_center"
        android:icon="@drawable/ic_format_align_center_black_24dp" />

    <item
        android:id="@+id/toggle_right"
        android:icon="@drawable/ic_format_align_right_black_24dp" />
</menu>

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:

val selectedToggles = toggleButtonLayout.selectedToggles()
//do what you need to with these selected toggles

And you can listen for when toggles are switched:

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:

<com.savvyapps.togglebuttonlayout.ToggleButtonLayout
    android:id="@+id/toggle_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_margin="16dp"
    app:allowDeselection="false"
    app:customLayout="@layout/view_toggle_button"
    app:dividerColor="@android:color/darker_gray"
    app:selectedColor="?attr/colorAccent"
    app:menu="@menu/toggles"
    app:multipleSelection="true"
    app:toggleMode="even" />

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].