• Stars
    star
    613
  • Rank 73,175 (Top 2 %)
  • Language
    Java
  • License
    Other
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

segmentcontrol widget for android

Android Arsenal jitpack Build Status License Download

中文

a simple SegmentControl Widget

art2

art1

使用:

添加依赖到build.gradle:

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 横向的边距
<com.sevenheaven.segmentcontrol.SegmentControl
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/segment_control"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"                       	
    android:textSize="18sp"
	app:block_direction="horizontal"
    app:selectedColor="#32ADFF"
	app:normalColor="#FFFFFF"
    app:textColors="@color/text_colors"
    app:backgroundColors="@color/background_color"
    app:cornerRadius="5dp"
    app:separatorWidth="2dp"
    app:boundWidth="4dp"
    app:texts="啊啊|啦啦啦|哈哈哈|顶顶顶顶"
    app:verticalGap="10dp"
    app:horizonGap="10dp"/>

使用OnSegmentControlClickListener来监听选中的变换

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

art2

art1

Usage:

add dependency to build.gradle:

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

<com.sevenheaven.segmentcontrol.SegmentControl
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/segment_control"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"                       	
    android:textSize="18sp"
	app:block_direction="horizontal"
    app:selectedColor="#32ADFF"
	app:normalColor="#FFFFFF"
    app:textColors="@color/text_colors"
    app:backgroundColors="@color/background_color"
    app:cornerRadius="5dp"
    app:separatorWidth="2dp"
    app:boundWidth="4dp"
    app:texts="啊啊|啦啦啦|哈哈哈|顶顶顶顶"
    app:verticalGap="10dp"
    app:horizonGap="10dp"/>

using OnSegmentControlClickListener to listen to segment change event.

mSegmentHorzontal = (SegmentControl) findViewById(R.id.segment_control);
mSegmentHorzontal.setOnSegmentControlClickListener(new SegmentControl.OnSegmentControlClickListener() {
    @Override
    public void onSegmentControlClick(int index) {
        Log.i(TAG, "onSegmentControlClick: index = " + index);
    }
});

More Repositories

1

bitmapMesh

bitmapMesh demo
Java
424
star
2

SHSwitchView

an iOS-7 Style Switch for android
Java
367
star
3

CurtainSlidingMenu

SlidingMenu With Curtain Effect
Java
317
star
4

GestureLock

a GestureLock that can customize length and style
Java
263
star
5

UILibrary

平时项目开发中写的自定义Drawable、View和Shape
Java
261
star
6

PullRefresh

IOS-style PullRefresh
Java
61
star
7

md2tv

Java
40
star
8

SHSoftwareRasterizer

软光栅器的简单实现
C++
31
star
9

ElegantUnderlineSpan

better underline style span based on romain guy's article https://medium.com/@romainguy/a-better-underline-for-android-90ba3a2e4fb#.tyhk99ywj and repo https://github.com/romainguy/elegant-underline
Java
22
star
10

Bezier

绘制任意阶数的贝塞尔曲线
Java
19
star
11

docktest

mac dock scale style custom view demo
Java
14
star
12

SHZoomView

provide a scaled View for any content on the screen
Java
13
star
13

libgif_comment

给libgif的lib下的代码文件增加注释,方便大家理解libgif的编码解码原理
C
11
star
14

ConfirmView

Java
10
star
15

metaball

Java
10
star
16

SHJavascriptInterface

javascriptinterface for iOS
Objective-C
8
star
17

leetcode_solutions

my solutions to leetcode questions
Java
6
star
18

w3m_iterm

w3m web browser with iterm img protocol support
C
5
star
19

QQ-jump

Java
5
star
20

Compass

IOS7 Style compass
Java
4
star
21

PaintView

A simple Demo for implement a paint board
Java
4
star
22

FC_source

FC原理图
HTML
3
star
23

CameraEffect

camera effect
C
2
star
24

deletedetect

C
2
star
25

RecyclerViewTest

Java
2
star
26

PCF8833-modify

给网上的PCF8833显示屏芯片驱动增加 Bresenham直线 & 吴小林抗锯齿直线绘制方法
C
1
star
27

EasyBitmapMesh

Java
1
star
28

StickableListView

nothing
Java
1
star
29

Waker

it's nothing
Java
1
star
30

jekyll_theme_thinny

HTML
1
star
31

FlipView

nothing yet
Java
1
star
32

perspectiveProject

Objective-C
1
star