VinsonGuo / AndroidSegmentControl

a android custom view like SegmentControl in IOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AndroidSegmentControl

Introduction

A android custom view works like SegmentControl in IOS

Usage

  • Add the below code in you layout xml file
<com.huibin.androidsegmentcontrol.SegmentControl
        xmlns:segmentcontrol="http://schemas.android.com/apk/res-auto"
        android:id="@+id/segment_control"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15sp"
        segmentcontrol:texts="未签到|全部|已签到" <!--标签的内容-->
        segmentcontrol:selectedBackgroundColors="#e00032"<!--被选中按钮的背景-->
        segmentcontrol:cornerRadius="5dip"
        segmentcontrol:direction="horizon" <!--标签的显示的方向-->
        segmentcontrol:verticalGap="8dip"
        segmentcontrol:horizonGap="8dip"
        segmentcontrol:selectedIndex="1"/><!--默认选中哪个标签,默认是0,当大于标签的个数就默认选中为最后一个标签-->
  • Then add these code
SegmentControl segmentControl = (SegmentControl) findViewById(R.id.segment_control);
segmentControl.setOnSegmentControlClickListener(new SegmentControl.OnSegmentControlClickListener() {
    @Override 
    public void onSegmentControlClick(int index) {
        //处理点击标签的事件
    } 
}); 
  • Enjoy yourself

Screen snapshot

snapshot

About

a android custom view like SegmentControl in IOS


Languages

Language:Java 100.0%