Code Monkey home page Code Monkey logo

segcontrol's Introduction

Segmented control button for Android

Implementation of a segmented control button for Android. A Segmented Control is really a better looking and more touch friendly version of a RadioButton. In fact, this implementation inherits from Android's default RadioButton.

The controls are customizable and themed in the fashion of the stock controls in Android 4.0 (Ice Cream Sandwich) and above.

The project contains a sample activity that shows how the buttons are implemented and styled.

Screenshot

Usage

You can use this library either with a theme or without a theme. With a theme is much easier but here are examples for both.

Theme

You can add the widget styles to your Theme in themes.xml and whenever you use either SegmentedControlButton or TabControlButton the theme will be automatically set!

values-v11/themes.xml:

<style name="CustomTheme" parent="@android:style/Theme.Holo">
    <item name="segmentedControlButtonStyle">@style/Widget.Holo.SegmentedControl</item>
    <item name="tabControlButtonStyle">@style/Widget.Holo.TabControl</item>
</style>

values/themes.xml:

<style name="CustomTheme" parent="@android:style/Theme">
    <item name="segmentedControlButtonStyle">@style/Widget.Holo.SegmentedControl</item>
    <item name="tabControlButtonStyle">@style/Widget.Holo.TabControl</item>
</style>

And in your layout:

<RadioGroup
    android:id="@+id/buttongroup1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <at.bookworm.widget.TabControlButton
        android:id="@+id/option1"
        android:text="Button 1" />

    <at.bookworm.widget.TabControlButton
        android:id="@+id/option2"
        android:text="Button 2" />
</RadioGroup>

No Theme

Instead of RadioButton, use either SegmentedControlButton or TabControlButton and set the widget's style to either Widget.Holo.SegmentedControlButton or Widget.Holo.TabControlButton. Since you aren't using a theme, you will have to set the style on every SegmentedControlButton and TabControlButton.

In your layout:

<RadioGroup
    android:id="@+id/buttongroup1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <at.bookworm.widget.TabControlButton
        android:id="@+id/option1"
        android:text="Button 1"
        style="@style/Widget.Holo.TabControlButton" />

    <at.bookworm.widget.TabControlButton
        android:id="@+id/option2"
        android:text="Button 2"
        style="@style/Widget.Holo.TabControlButton" />
</RadioGroup>

segcontrol's People

Contributors

grantland avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.