# SegmentedControl
**Repository Path**: wangyin6688/SegmentedControl
## Basic Information
- **Project Name**: SegmentedControl
- **Description**: No description available
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-06-23
- **Last Updated**: 2021-07-30
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Android SegmentedControl + multi row support + multi selection
### minSdk API 14+

[Demo App, Play store link](https://play.google.com/store/apps/details?id=segmented_control.widget.custom.android.com.segmentedcontrolexample&hl=en)
[Or try demo App online !](https://appetize.io/app/y4e91xhxgp47956bf73da4z4yg)
[](https://jitpack.io/#RobertApikyan/SegmentedControl)
[](https://opensource.org/licenses/Apache-2.0)
## Segmented control for Android, with a lot of customization properties
## ScreenShots
## Download
### Gradle
Add to project level build.gradle
```groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Add dependency to app module level build.gradle
```groovy
dependencies {
implementation 'com.github.RobertApikyan:SegmentedControl:1.2.0'
}
```
### Maven
```xml
jitpack.io
https://jitpack.io
```
Add dependency
```xml
com.github.RobertApikyan
SegmentedControl
1.1.3
```
### Done.
## Simple usage in XML
```xml
```
Attributes
```xml
setSupportedSelectionsCount(int)
setDistributeEvenly(boolean)
setDistributeEvenly(boolean)
setColumnCount(int)
addSegments(Object[]), addSegments(List)
setSelectedStrokeColor(int)
setUnSelectedStrokeColor(int)
setSelectedBackgroundColor(int)
setUnSelectedBackgroundColor(int)
setSelectedTextColor(int)
setUnSelectedTextColor(int)
setTextSize(int)
setTextHorizontalPadding(int)
setTextVerticalPadding(int)
setSegmentVerticalMargin(int)
setSegmentHorizontalMargin(int)
setRadius(int)
setTopLeftRadius(int)
setTopRightRadius(int)
setBottomRightRadius(int)
setBottomLeftRadius(int)
setRadiusForEverySegment(boolean)
setTypeFace(TypeFace)
```
**Note:** After every configuration change call segmentedControl.notifyConfigIsChanged() method
# Example
```java
segmentedControl.setStrokeWidth(width.intValue());
segmentedControl.setColumnCount(columnCount);
segmentedControl.notifyConfigIsChanged();
```
> SegmentedControl uses SegmentAdapter and SegmentViewHolder for displaying segments. There are allready exist a default implementations for SegmentAdapter (SegmentAdapterImpl) and SegmentViewHolder (SegmentViewHolderImpl), but if you want to make your custom implementation... well here is the steps
1. Define `segment_item.xml` inside `layouts` folder
```xml
```
2. Create a `SegmentViewHolder` instance (`AppSegmentViewHolder`) (here I define the segment generic data type as a String)
```java
public class AppSegmentViewHolder extends SegmentViewHolder {
TextView textView;
public AppSegmentViewHolder(@NonNull View sectionView) {
super(sectionView);
textView = (TextView) sectionView.findViewById(R.id.text_view);
}
@Override
protected void onSegmentBind(String segmentData) {
textView.setText(segmentData);
}
}
```
3. Create a `SegmentAdapter` instance
```java
public class AppSegmentAdapter extends SegmentAdapter {
@NonNull
@Override
protected AppSegmentViewHolder onCreateViewHolder(@NonNull LayoutInflater layoutInflater, ViewGroup viewGroup, int i) {
return new AppSegmentViewHolder(layoutInflater.inflate(R.layout.item_segment, null));
}
}
```
4. Pass the adapter to the segmentedControl
```java
segmentedControl = (SegmentedControl) findViewById(R.id.segmented_control);
segmentedControl.setAdapter(new AppSegmentAdapter());
```
5. Finally add segments data.
```java
segmentedControl.addSegments(getResources().getStringArray(R.array.segments));
```
That's it :)
For custom implementation use `SegmentedControlUtils` helper class in order to define segment background type and background radius.
[](https://www.linkedin.com/in/robert-apikyan-24b915130/)
License
-------
Copyright 2017 Robert Apikyan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.