Option Switch entry-third-party open-source-SHSegmentControl, open-source third-party platform
Home address of SHSegmentControl on github project: https://github.com/7heaven/SHSegmentControl
SHSegmentControl is easy to use and can be configured in the xml layout file. For example, segmentcontrol: texts = "A | B | C | D"
That is, the text in the Option Switch bar.
The test code is as follows:
Activity_main.xml:
1 <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 2 xmlns: tools = "http://schemas.android.com/tools" 3 android: layout_width = "match_parent" 4 android: layout_height = "match_parent" 5 android: orientation = "vertical"> 6 7 <! -- Segmentcontrol: cornerRadius = "5dip" sets the edge corner --> 8 <! -- Segmentcontrol: horizonGap = "20dip" sets the horizontal width --> 9 <! -- Segmentcontrol: verticalGap = "8dip" sets the vertical width of a unit --> 10 <! -- Segmentcontrol: direction = "horizon" sets the horizontal width of a unit --> 11 12 <com. sevenheaven. segmentcontrol. segmentControl13 xmlns: segmentcontrol = "http://schemas.android.com/apk/res-auto" 14 android: id = "@ + id/segment_control_horizon" 15 android: layout_width = "wrap_content" 16 android: layout_height = "wrap_content" 17 android: layout_gravity = "center_horizontal" 18 android: textSize = "15sp" 19 segmentcontrol: colors = "# 0099CC" 20 segmentcontrol: cornerRadius = "10dip" 21 segmentcontrol: direction = "horizon" 22 segmentcontrol: horizonGap = "20dip" 23 segmentcontrol: texts = "A | B | C | D" 24 segmentcontrol: verticalGap = "8dip"/> 25 26 <TextView27 android: id = "@ + id/textView" 28 android: layout_width = "wrap_content" 29 android: layout_height = "wrap_content" 30 android: layout_gravity = "center_horizontal" 31 android: paddingTop = "20dp" 32 android: text = "A" 33 android: textColor = "@ android: color/holo_red_light "34 android: textSize =" 50sp "/> 35 36 37 <com. sevenheaven. segmentcontrol. segmentControl38 xmlns: segmentcontrol = "http://schemas.android.com/apk/res-auto" 39 android: id = "@ + id/segment_control_vertical" 40 android: layout_width = "wrap_content" 41 android: layout_height = "wrap_content" 42 android: layout_gravity = "center_horizontal" 43 android: textSize = "15sp" 44 segmentcontrol: colors = "@ android: color/holo_orange_light" 45 segmentcontrol: cornerRadius = "10dip" 46 segmentcontrol: direction = "vertical" 47 segmentcontrol: horizonGap = "10dip" 48 segmentcontrol: texts = "A | B | C | D" 49 segmentcontrol: verticalGap = "20dip"/> 50 51 <TextView52 android: id = "@ + id/textView1" 53 android: layout_width = "wrap_content" 54 android: layout_height = "wrap_content" 55 android: layout_gravity = "center_horizontal" 56 android: paddingTop = "20dp" 57 android: text = "A" 58 android: textColor = "@ android: color/holo_green_light "59 android: textSize =" 50sp "/> 60 61 </LinearLayout>Activity_main.xml
MainActivity. java:
1 package com. zzw. testsegmentcontrol; 2 3 import com. sevenheaven. segmentcontrol. segmentControl; 4 import com. sevenheaven. segmentcontrol. segmentControl. onSegmentControlClickListener; 5 6 import android. app. activity; 7 import android. OS. bundle; 8 import android. util. log; 9 import android. widget. textView; 10 11 public class MainActivity extends Activity {12 13 @ Override14 protected void onCreate (Bundle savedInstanceState) {15 super. onCreate (savedInstanceState); 16 setContentView (R. layout. activity_main); 17 18 final TextView textView = (TextView) findViewById (R. id. textView); 19 final TextView textView1 = (TextView) findViewById (R. id. textView1); 20 21 SegmentControl segment_control_horizon = (SegmentControl) findViewById (R. id. segment_control_horizon); 22 SegmentControl segment_control_vertical = (SegmentControl) findViewById (R. id. segment_control_vertical); 23 24 segment_control_horizon25. setOnSegmentControlClickListener (new OnSegmentControlClickListener () {26 27 @ Override28 public void onSegmentControlClick (int index) {29 Log. d ("horizon-current location", index + ""); 30 switch (index) {31 case 0: 32 textView. setText ("A"); 33 break; 34 case 1: 35 textView. setText ("B"); 36 break; 37 case 2: 38 textView. setText ("C"); 39 break; 40 case :41 textView. setText ("D"); 42 break; 43} 44} 45}); 46 47 segment_control_vertical48. setOnSegmentControlClickListener (new OnSegmentControlClickListener () {49 50 @ Override51 public void onSegmentControlClick (int index) {52 Log. d ("vertical-current location", index + ""); 53 switch (index) {54 case 0: 55 textView1.setText ("A"); 56 break; 57 case 1: 58 textView1.setText ("B"); 59 break; 60 case 2: 61 textView1.setText ("C"); 62 break; 63 case 3: 64 textView1.setText ("D "); 65 break; 66} 67} 68}); 69} 70}