Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/malekkamel/android-multitoggle
A simple multi-state toggle button for Android.
https://github.com/malekkamel/android-multitoggle
android-library android-ui java-8 toggle-buttons
Last synced: 2 months ago
JSON representation
A simple multi-state toggle button for Android.
- Host: GitHub
- URL: https://github.com/malekkamel/android-multitoggle
- Owner: MalekKamel
- Created: 2018-08-26T08:49:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-08T03:47:27.000Z (over 6 years ago)
- Last Synced: 2024-10-09T11:04:33.627Z (4 months ago)
- Topics: android-library, android-ui, java-8, toggle-buttons
- Language: Java
- Size: 513 KB
- Stars: 19
- Watchers: 1
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MultiToggleButton
### A simple Android multi toggle button![alt text](https://github.com/ShabanKamell/android-multitoggle/blob/master/blob/master/raw/mtb_example.png "Sample App")
# Installation
[ ![Download](https://api.bintray.com/packages/shabankamel/android/multitogglebutton/images/download.svg) ](https://bintray.com/shabankamel/android/multitogglebutton/_latestVersion)
```groovy
dependencies {
implementation 'com.sha.kamel:multi-toggle-button:1.8.3@aar'
}allprojects {
repositories {
maven { url "https://dl.bintray.com/shabankamel/android" }
}
}
```
# UsageAdd a button to layout:
```xml```
## Listen to item selection
```java
mtb.setOnItemSelectedListener((toggleButton, item, index, label, selected) -> {
toast(selected ? "selected" : "deselected"));
});
```
## Get selected items
You can get selected items.
```java
Selected selected = toggleButton.getSelected();boolean isAnySelected = selected.isAnySelected();
boolean isAllSelected = selected.isAllSelected();
boolean isSingleItem = selected.isSingleItem();int singleItemPosition = selected.getSingleItemPosition();
TextView singleItem = selected.getSingleItem();List selectedItems = selected.getSelectedItems();
List selectedPositions = selected.getSelectedPositions();
```
## Colors
You can select any desired color for different states.
```java
mtb.setColorRes(R.color.mtb_green, R.color.mtb_gray);
```
There're many methods to set colors. Take a look at `ToggleButton`## Rounded corners
you can set corners rounded:
```java
mtb.setRoundedCorners();
```## Corners Radius
You can set a default radius of `18dp` :
```java
mtb.setCornerRadius(20);
```##### Note:
if you set corner radius with `setCornerRadius`, no need to call `setRoundedCorners`.## Multiple Choice
```java
mtb.multipleChoice(true)
```## Max items to select
you can set the maximum items allowed to be selected
```java
mtb.maxSelectedItems(2, max -> toast("Can't select more than " + max + " items."));
```
#### Note
if you call `maxSelectedItems`, no need to set `multipleChoice(true)`.## Scroll
You can scroll `MultiToggleButton` if the views are out of bounds
```java
mtb.setScrollable(true);
```
#### Note
The scroll is disabled by default.# Attributes:
| Attribute name | Description |
| ----------------|------------------------|
| labels | Labels of each items in button
| mtbPressedColor | Color of pressed button
| mtbUnpressedColor | Color of unpressed button
| mtbColorPressedText | Color of text for pressed button
| mtbColorUnpressedText | Color of text for un pressed button
| mtbCornerRadius | Corner radius
| mtbRoundedCorners | If true, the corners will be rounded. If corner radius is not set a default radius 18 will be set.
| mtbMultipleChoice | multiple items choice. The default is false.
| mtbScrollable | If true, items will be scrollable if it's out of screen bounds. The default is false
| mtbSelectFirstItem | If true, first item will be selected. The default is true.
| mtbTextAllCaps | All text caps.The default is true.### See 'app' module for the full code.
# License
## Apache license 2.0