A multi-state toggle button for Android
A multi-state toggle button for Android
A simple multi-state toggle button for Android.
Any help is appreciated :)
dependencies {
compile 'org.honorato.multistatetogglebutton:multistatetogglebutton:0.2.2'
}Then in your activity's XML:
You can change change colors via xml (see above) or programmatically :
MultiStateToggleButton button = (MultiStateToggleButton) this.findViewById(R.id.mstb_multi_id);
button.setColorRes(R.color.color_pressed, R.color.color_released);If you don't specify any values, default colors are taken from ?attr:colorPrimary and ?attr:colorControlNormal
If you need a callback for when the value changes then add this to your code:
MultiStateToggleButton button = (MultiStateToggleButton) this.findViewById(R.id.mstb_multi_id);
button.setOnValueChangedListener(new ToggleButton.OnValueChangedListener() {
@Override
public void onValueChanged(int position) {
Log.d(TAG, "Position: " + position);
}
});Be sure to declare an array of strings called planets_array in your strings.xml:
Mer
Venus
Earth
Mars
The values can also be specified programmatically, plus other options:
MultiStateToggleButton button = (MultiStateToggleButton) this.findViewById(R.id.mstb_multi_id);
// With an array
CharSequence[] texts = new CharSequence[]{"abc", "def"};
button.setElements(texts);
// With a resource id
button.setElements(R.array.planets_array);
// Resource id, position one is selected by default
button.setElements(R.array.dogs_array, 1);
// Multiple elements can be selected simultaneously
button.enableMultipleChoice(true);In order to use arbitrary buttons (e.g. ImageButton)
…No open issues yet, or sync has not completed.