Home

Awesome

Android Arsenal

Archived

I stopped developing this library for a long time ago. I thought about revising it recently but there is already someone keeping it up. I recommend you to use it instead. Thank you all for your support.

https://github.com/addisonElliott/SegmentedButton

SegmentedButton

poster

Segmented Button is a IOS-like "Segmented Control" with animation.<br/> For more Android-like segmented control, check Radio Real Button.

Preview

1 <br /> 2 <br /> 3 <br /> 6 <br /> 4 5 <br />

You can also apply your custom drawable on button group

7 <br />

It is now possible to drag selector

8

Installation

Gradle

Add it to your build.gradle with:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

and:

dependencies {
    compile 'com.github.ceryle:SegmentedButton:v2.0.2'
}

Customization

Some Attributes

Segmented Button

Option NameFormatDescription
app:sb_imageTintcolorSet tint onto button's image
app:sb_imageScalefloatScale button's image
app:sb_selectedImageTintcolorSet tint onto button's image if selector on it
app:sb_selectedTextColorcolorSet color onto button's text if selector on it
app:sb_rippleColorcolorSet ripple color of button

Segmented Button Group

Option NameFormatDescription
app:sbg_ripplebooleanSet ripple color for every button
app:sbg_rippleColorcolorSet ripple color for every button with custom color
app:sbg_selectorImageTintcolorIf selector on it, set tint onto image for every button
app:sbg_selectorTextColorcolorIf selector on it, set text color for every button
app:sbg_selectorColorcolorSet selector color
app:sbg_dividerSizedimensionSet divider size
app:sbg_dividerPaddingdimensionSet divider padding for top and bottom
app:sbg_dividerColorcolorChange divider color
app:sbg_dividerRadiusdimensionRound divider
app:sbg_shadowbooleanShadow for container layout (api21+)
app:sbg_shadowElevationdimensionShadow for container layout (api21+)
app:sbg_shadowMargindimensionSet margin to make shadow visible (api21+)
app:sbg_positionintegerSet selected button position
app:sbg_radiusdimensionMake layout rounder
app:sbg_backgroundColorcolorSet background color of container (except transparent color)
app:sbg_animateSelectorDurationintegerSet how long selector travels to selected position
app:sbg_animateSelectorintegerSet selector animation (ex. bounce animation)
app:sbg_borderSizedimensionAdd border by giving dimension
app:sbg_borderColorcolorChange border color (Default: Grey)

Animations Available

These animations can be set using the attribute noted above like so: app:sbg_animateSelector="bounce". Also make sure to play with the app:sbg_animateSelectorDuration attribute to get the animation to look exactly how you want it.

Examples

In Xml Layout
    <co.ceryle.segmentedbutton.SegmentedButtonGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        app:sbg_animateSelector="bounce"
        app:sbg_animateSelectorDuration="1000"
        app:sbg_backgroundColor="@color/white"
        app:sbg_dividerColor="@color/grey_500"
        app:sbg_dividerPadding="10dp"
        app:sbg_dividerRadius="10dp"
        app:sbg_dividerSize="1dp"
        app:sbg_position="1"
        app:sbg_radius="2dp"
        app:sbg_ripple="true"
        app:sbg_rippleColor="@color/grey_500"
        app:sbg_selectorColor="@color/grey_500"
        app:sbg_selectorTextColor="@color/white"
        app:sbg_shadow="true"
        app:sbg_shadowElevation="3dp"
        app:sbg_shadowMargin="4dp">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minHeight="10dp"
            android:text="Button 1"
            android:textAllCaps="false" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minHeight="10dp"
            android:text="Button 2"
            android:textAllCaps="false" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minHeight="10dp"
            android:text="Button 3"
            android:textAllCaps="false" />

    </co.ceryle.segmentedbutton.SegmentedButtonGroup>
Listener Example
SegmentedButtonGroup segmentedButtonGroup = (SegmentedButtonGroup) findViewById(R.id.segmentedButtonGroup);
segmentedButtonGroup.setOnClickedButtonPosition(new SegmentedButtonGroup.OnClickedButtonPosition() {
    @Override
    public void onClickedButtonPosition(int position) {
        Toast.makeText(MainActivity.this, "Clicked: " + position, Toast.LENGTH_SHORT).show();
    }
});
segmentedButtonGroup.setPosition(2, 0);

License

This project is licensed under the Apache License Version 2.0 - see the LICENSE.md file for details