GithubHelp home page GithubHelp logo

sheng930920 / androidcheckablebutton Goto Github PK

View Code? Open in Web Editor NEW

This project forked from liangfeidotme/androidcheckablebutton

0.0 2.0 0.0 479 KB

Android buttons in various styles

License: Apache License 2.0

Java 98.17% Shell 1.83%

androidcheckablebutton's Introduction

AndroidCheckableButton

A simple button which implements the Checkable interface.

It behaves like a CheckBox, but can also be used as a Button.

The button behaving like RadioButton, and layout behaving like RadioGroup will be added soon. :)

Demo

Usage

The usage of CheckableButton is exactly the same as Button, but in order to achive the UI of the demo, you need to do a little more work.

Create two shapes for borders in default and selected status

checkable_default_border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:width="1dp" android:color="#DDDDDD" />
    <corners android:radius="2dp" />
    <solid android:color="@android:color/white" />
</shape>

checkable_selected_border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke android:color="#ED2727" android:width="1dp" />
    <corners android:radius="2dp" />
    <solid android:color="@android:color/white" />
</shape>

Create a selector used as the background

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/checkable_selected_border" />
    <item android:drawable="@drawable/checkable_default_border" />
</selector>

You can also create a color selector for text color

checkable_text_color.xml placed in res/color directory.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:color="@android:color/darker_gray" />
    <item android:state_checkable="true" android:color="@android:color/darker_gray"/>
    <item android:color="@android:color/darker_gray"/>
</selector>

Apply the defined resource files

<com.liangfeizc.flowlayout.FlowLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginTop="10dp"
    app:horizontal_spacing="18dp"
    app:vertical_spacing="10dp">

    <com.liangfeizc.checkablebutton.CheckableButton
        android:layout_width="88dp"
        android:layout_height="32dp"
        android:background="@drawable/checkable_background"
        android:text="衣物"
        android:textColor="@color/checkable_text_color"
        android:textSize="14sp" />

    <com.liangfeizc.checkablebutton.CheckableButton
        android:layout_width="88dp"
        android:layout_height="32dp"
        android:background="@drawable/checkable_background_secondary"
        android:text="帽子"
        android:textColor="@color/checkable_text_color"
        android:textSize="14sp" />
</com.liangfeizc.flowlayout.FlowLayout>

Me

License

MIT

androidcheckablebutton's People

Contributors

liangfeidotme avatar

Watchers

James Cloos avatar Andy 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.