SHSegmentControl


Source link: https://github.com/7heaven/SHSegmentControl

??

a simple SegmentControl Widget

???

?????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

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);

  
}
 
}
);

Resources

Attempting to make convenient for working with ViewPager and PagerAdatper.

Android library for grabbing info from link using reactive way.

"Favor composition over inheritance" for ListView.

This library intends to help developers to parse QR text returned from any QR reader to an elegant form which you can display in a TextView.

This plugin add an inspection that check if Activity implements following method.

A small library containing two adapters which allow for easy fragment management with a NavigationView.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes