Skip to content

CodeManLH/SegmentedControl

Repository files navigation

SegmentedControl

Android SegmentedControl

**API(14+)

Download

Gradle

Add it in your root build.gradle at the end of repositories:

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

Add dependency to app module level build.gradle

dependencies {
    implementation 'com.github.CodeManLH:SegmentedControl:1.0.0'
}

Maven

<repositories>
    <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
    </repository>
</repositories>

Add the dependency

<dependency>
    <groupId>com.github.CodeManLH</groupId>
        <artifactId>SegmentedControl</artifactId>
    <version>Tag</version>
</dependency>

Done.

Simple usage in XML

    <com.jw0ng.widget.SegmentedControl
        android:id="@+id/sg_control"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        app:selectedIndex="0">

        <com.jw0ng.widget.Segmented
            android:layout_width="0dp"
            android:layout_height="match_parent"
            app:text="Complete"
            app:description="0"/>

        <com.jw0ng.widget.Segmented
            android:layout_width="0dp"
            android:layout_height="match_parent"
            app:text="Undone"
            app:description="0" />
        
        ...
        
    </com.jw0ng.widget.SegmentedControl>

SegmentedControl Attributes

Change Color

app:tintColor="@color/colorPrimary"

Line Width

app:strokeWidth="2px"

Corner Radius

app:cornerRadius="5dp"

Init Selected Index

app:selectedIndex="0"

Segmented Attributes

Top Text

app:text="Complete"

Bottom Text (if you don't need the instructions below, no setting will automatically hide)

app:description="0"

Font Size (default 12sp)

app:textSize="16sp"
app:descriptionSize="13sp"

Text Color ('textColor' is the normal color)

app:textColor="@color/colorPrimary"
app:textSelectedColor="@color/colorAccent"
app:descriptionColor="@color/colorPrimaryDark"
app:descriptionSelectedColor="@color/colorAccent"

Example

segmentedControl = findViewById(R.id.sg_control);
segmentedControl.setOnItemSelectedListener(new SegmentedControl.OnItemSelectedListener() {
    @Override
    public void onItemSelected(Segmented segmented, int index) {
        switch (index) {
            case 0:
                Log.v(TAG,index + "");
                Log.v(TAG,segmented.getText());
                break;
            case 1:
                segmented.setDescription("1");
                break;
        }

    }
});

About

Android SegmentedControl

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages