https://github.com/7heaven/SHSegmentControl
segmentcontrol widget for android
https://github.com/7heaven/SHSegmentControl
radiogroup segmentcontrol selector
Last synced: 5 months ago
JSON representation
segmentcontrol widget for android
- Host: GitHub
- URL: https://github.com/7heaven/SHSegmentControl
- Owner: 7heaven
- License: other
- Created: 2015-04-22T11:17:39.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-02-28T06:43:58.000Z (about 3 years ago)
- Last Synced: 2024-08-02T01:23:55.162Z (9 months ago)
- Topics: radiogroup, segmentcontrol, selector
- Language: Java
- Homepage:
- Size: 258 KB
- Stars: 611
- Watchers: 20
- Forks: 143
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-android-ui - SHSegmentControl - 一个简单的SegmentControl部件 (分段控件)
- awesome-android-ui - https://github.com/7heaven/SHSegmentControl
- awesome-android-ui - https://github.com/7heaven/SHSegmentControl
README
[](http://android-arsenal.com/details/1/1770) [](https://img.shields.io/github/release/7heaven/SHSegmentControl.svg?label=JitPack%20Maven) [](https://travis-ci.org/7heaven/SHSegmentControl)
[](LICENSE)
[  ](https://bintray.com/7heaven/maven/SHSegmentControl/_latestVersion)### 中文
# a simple SegmentControl Widget


## 使用:
### 添加依赖到build.gradle:
```groovy
dependencies {
compile 'com.7heaven.widgets:segmentcontrol:1.17'
}
```**相关属性:**
* **selectedColor** 设置选中后的颜色
* **normalColor** 设置未选中的颜色
* **textColors** 设置文字内容的颜色,可以使用ColorStateList来设置选中和未选中的颜色,这个属性设置以后,之前设置的selectedColor和normalColor对文字内容失去作用
* **backgroundColors** 设置边框、选中的背景和分割线的颜色,可以使用ColorStateList来同事设置选中和未选中的颜色,和textColors一样,设置这个属性后,selectedColor和normalColor会对边框和背景失去作用
* **cornerRadius** 设置背景的圆角半径
* **boundWidth** 设置边框的粗细
* **separatorWidth** 设置分割线的粗细
* **texts** 设置文字内容,通过'|'分隔开
* **verticalGap** 纵向上的边距
* **horizonGap** 横向的边距``` xml
```
使用OnSegmentControlClickListener来监听选中的变换
```java
mSegmentHorzontal = (SegmentControl) findViewById(R.id.segment_control);
mSegmentHorzontal.setOnSegmentControlClickListener(new SegmentControl.OnSegmentControlClickListener() {
@Override
public void onSegmentControlClick(int index) {
Log.i(TAG, "onSegmentControlClick: index = " + index);
}
});
```### English
# a simple SegmentControl Widget


## Usage:
### add dependency to build.gradle:
```groovy
dependencies {
compile 'com.7heaven.widgets:segmentcontrol:1.16'
}
```**Attributes:**
* **selectedColor** attribute for setting the selected color
* **normalColor** attribute for setting the unselected color
* **textColors** attribute for setting text colors, this attribute accept ColorStateList so you can set text selected color & text unselected color using this attribute,once this attribute is set, the previously selectedColor & normalColor attributes will not affect the text color
* **backgroundColors** for setting the round corner background stroke color, separators color & selected background color,same as textColors, when this attribute is set, previously selectedColor & normalColor attributes will not affect the background color, this attribute accept ColorStateList
* **cornerRadius** setting the corner radius of the background
* **boundWidth** setting the round corner background stroke width
* **separatorWidth** setting width of separators
* **texts** setting the string contents, separated by '|'
* **verticalGap** vertical padding
* **horizonGap** horizontal padding**noticed that textColors & backgroundColors has higher priority than selectedColor & normalColor**
``` xml
```
using OnSegmentControlClickListener to listen to segment change event.
```java
mSegmentHorzontal = (SegmentControl) findViewById(R.id.segment_control);
mSegmentHorzontal.setOnSegmentControlClickListener(new SegmentControl.OnSegmentControlClickListener() {
@Override
public void onSegmentControlClick(int index) {
Log.i(TAG, "onSegmentControlClick: index = " + index);
}
});
```