segmentcontrol widget for android

Overview

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);
    }
});
You might also like...
TourGuide is an Android library that aims to provide an easy way to add pointers with animations over a desired Android View

TourGuide TourGuide is an Android library. It lets you add pointer, overlay and tooltip easily, guiding users on how to use your app. Refer to the exa

Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.
Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.

Bubbles for Android Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your

View that imitates Ripple Effect on click which was introduced in Android L  (for Android 2.3+)
View that imitates Ripple Effect on click which was introduced in Android L (for Android 2.3+)

RippleView View that imitates Ripple Effect on click which was introduced in Android L. Usage For a working implementation, Have a look at the Sample

A new canvas drawing library for Android. Aims to be the Fabric.js for Android. Supports text, images, and hand/stylus drawing input. The library has a website and API docs, check it out

FabricView - A new canvas drawing library for Android. The library was born as part of a project in SD Hacks (www.sdhacks.io) on October 3rd. It is cu

MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.
MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

About MarkdownView (Markdown For Android) is an Android library that helps you display Markdown text or files (local/remote) as formatted HTML, and st

SwipeBack for Android Activities to do pretty the same as the android
SwipeBack for Android Activities to do pretty the same as the android "back-button" will do, but in a really intuitive way by using a swipe gesture

SwipeBack SwipeBack is for Android Activities to do pretty the same as the android "back-button" will do, but in a really intuitive way by using a swi

A backport of the SwitchPreference component that was introduced on Android 4 (ICS / level 14). This port works on Android 2.1+ (Eclair MR1 / level 7).

Android Switch Preference Backport A backport of the SwitchPreference component that was introduced on Android 4 (ICS / level 14). This port works on

Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (https://github.com/romannurik/android-wizardpager)
Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (https://github.com/romannurik/android-wizardpager)

Wizard Pager Wizard Pager is a library that provides an example implementation of a Wizard UI on Android, it's based of Roman Nurik's wizard pager (ht

Sample project created to show some of the best Android practices to work in the Android UI Layer. The UI layer of this project has been implemented using MVP or MVVM (without binding engine) to show how this patterns works. This project is used during the talk
Comments
  • Class not instantiating

    Class not instantiating

    Hey. I want to use your library in my project but I'm getting this error when implementing the view in layout xml file. The error goes:

    java.lang.NullPointerException
        at com.sevenheaven.segmentcontrol.SegmentControl.<init>(SegmentControl.java:118)
        at com.sevenheaven.segmentcontrol.SegmentControl.<init>(SegmentControl.java:78)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:413)
        at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)
        at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:176)
        at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
        at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
        at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:400)
        at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:332)
        at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
        at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:708)
        at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:697)
        at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
        at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:697)
        at com.android.tools.idea.rendering.RenderService.render(RenderService.java:816)
        at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:646)
        at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:82)
        at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:589)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
        at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
        at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:584)
        at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
        at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
        at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
        at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
        at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
        at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
        at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
        at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    

    Also I get this error when launching the activity containing the object:

    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.sevenheaven.segmentcontrol.SegmentControl.setOnSegmentControlClickListener(com.sevenheaven.segmentcontrol.SegmentControl$OnSegmentControlClickListener)' on a null object reference
    
    opened by ghost 1
  • Fix broken headings in Markdown files

    Fix broken headings in Markdown files

    GitHub changed the way Markdown headings are parsed, so this change fixes it.

    See bryant1410/readmesfix for more information.

    Tackles bryant1410/readmesfix#1

    opened by bryant1410 0
  • Multiple quality improvements - squid:SwitchLastCaseIsDefaultCheck, s…

    Multiple quality improvements - squid:SwitchLastCaseIsDefaultCheck, s…

    This pull request is focused on resolving occurrences of Sonar rules squid:SwitchLastCaseIsDefaultCheck - "switch" statements should end with a "default" clause squid:S00121 - Control structures should use curly braces squid:S1068 - Unused private fields should be removed

    You can find more information about the issues here: https://dev.eclipse.org/sonar/coding_rules#q=squid:SwitchLastCaseIsDefaultCheck https://dev.eclipse.org/sonar/coding_rules#q=squid:S00121 https://dev.eclipse.org/sonar/coding_rules#q=squid:S1068

    Please let me know if you have any questions.

    M-Ezzat

    opened by m-ezzat 0
Releases(1.17)
Owner
7heaven
啊呜~
7heaven
An Android Widget for selecting items that rotate on a wheel.

Looking for maintainers I'm no longer active on this project but I'll still focus on fixing crashing issues and review any code changes etc. WheelView

Luke Deighton 888 Jan 3, 2023
Android Thermometer Widget.

Thermometer Android Thermometer Widget. Developer Kofi Gyan ([email protected]) License Copyright 2016 Kofi Gyan. Licensed under the Apache Licen

Kofi Gyan 125 Nov 17, 2022
Custom wheel widget for android

Wheel widget for Android To include the wheel widget in the current layout, you should add in the layout xml this lines: <it.sephiroth.android

Alessandro Crugnola 384 Nov 21, 2022
Android Widget

Circular Counter Circular Counter is an Android Widget I needed to implement for an application I was developing. As it could be useful to more people

Diogo Bernardino 254 Nov 25, 2022
A Pin view widget for Android

PinView A Pin view widget for Android. PinView has a feature that allows you to find out when they have completed all parameters. Support for Android

David Pizarro 287 Nov 14, 2022
This is a sample Android Studio project that shows the necessary code to create a note list widget, And it's an implementation of a lesson on the Pluralsight platform, but with some code improvements

NoteKeeper-Custom-Widgets This is a sample Android Studio project that shows the necessary code to create a note list widget, And it's an implementati

Ibrahim Mushtaha 3 Oct 29, 2022
A library that provides an implementation of the banner widget from the Material design.

MaterialBanner A banner displays a prominent message and related optional actions. MaterialBanner is a library that provides an implementation of the

Sergey Ivanov 252 Nov 18, 2022
It's a flip way to show share widget.

What's FlipShare ? It's a cool way to show share widget. Demo Usage step 1. Confirm your parentView to locate the share widget, and then you can custo

巴掌 630 Sep 5, 2022
TabSlider - An expanding slider widget which displays selected value

TabSlider - An expanding slider widget which displays selected value

null 1 Apr 20, 2022
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.

Draggable Panel DEPRECATED. This project is not maintained anymore. Draggable Panel is an Android library created to build a draggable user interface

Pedro Vicente Gómez Sánchez 3k Dec 6, 2022