A nicer-looking, more intuitive and highly customizable alternative for radio buttons and dropdowns for Android.
A nicer-looking, more intuitive and highly customizable alternative for radio buttons and dropdowns for Android.
Bored of dull looking radio buttons and dropdowns? Me too. I started looking for a more sophisticated way of offering user a choice, and came up with this beautiful dribble.
Unfortunately, there were no ready-made solutions to achieve this, so I spent a good day working on this very thing I call SwipeSelector.
SwipeSelector supports API levels all the way down to 8 (Android Froyo).
Gradle:
compile 'com.roughike:swipe-selector:1.0.6'Maven:
com.roughike
swipe-selector
1.0.6
pom
The usage is really simple.
First add SwipeSelector to your layout file:
Then get a hold of it and give it a set of SwipeItem objects with values, titles and descriptions:
…Whenever you need to know what is the currently showing SwipeItem:
SwipeItem selectedItem = swipeSelector.getSelectedItem();
// The value is the first argument provided when creating the SwipeItem.
int value = (Integer) selectedItem.value;
// for example
if (value == 0) {
// The user selected slide number one.
}For an example project using multiple SwipeSelectors, refer to the sample app.
swipe_indicatorSize the size for the circle indicators.
swipe_indicatorMargin how far the indicators are from each other.
swipe_indicatorInActiveColor the color for normal unselected indicators.
swipe_indicatorActiveColor the color for selected indicator.
swipe_leftButtonResource and swipe_rightButtonResource custom Drawable resources for the left and right buttons. The margins for the content are calculated automatically, so even a bigger custom image won't overlap the content.
swipe_customFontPath path for your custom font file, such as fonts/MySuperDuperFont.ttf. In that case your font path would look like src/main/assets/fonts/MySuperDuperFont.ttf, but you only need to provide fonts/MySuperDuperFont.ttf, as the asset folder will be auto-filled for you.
swipe_titleTextAppearance and swipe_descriptionTextAppearance custom TextAppearance for the title and description TextViews for modifying the font sizes and colors and what not.
swipe_descriptionGravity custom horizontal gravity (in other words alignment) for the description text. Can be either left, center or right. Default should be fine in most cases, but sometimes you might need to modify this.
Send me a pull request with modified README.md to get a shoutout!
Feel free to create issues / pull requests.
…No open issues yet, or sync has not completed.