GithubHelp home page GithubHelp logo

joegana / iconbutton Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pnc/iconbutton

0.0 2.0 0.0 768 KB

A Button subclass for Android that provides better control over drawable positioning

License: Apache License 2.0

Java 100.00%

iconbutton's Introduction

IconButton for Android

IconButton is an Android button widget that allows you to center both the button's text and an icon.

Android's stock Button class allows you to assign a Drawable to the left, right, top, or bottom of a button, but it looks bad if you need to have the button fill the screen:

Default Android Button Behavior

Installation

For Gradle / Android Studio

Make sure you declare the JCenter repository in your project's build.gradle:

repositories {
    jcenter()
}

Then add a compile-time dependency on this library, adding the dependencies section to build.gradle if it doesn't already exist:

dependencies {
    compile 'com.githang:com-phillipcalvin-iconbutton:1.0.1@aar'
}

For Old Version

If you're using ADT, clone this repository and import it into your workspace using File - Import. Then add it to your project by right-clicking your project, selecting Properties, then Android, and adding IconButton in the references list at the bottom of the Properties window.

If you're not using ADT, I recommend using this library as a submodule:

git submodule add [email protected]:pnc/IconButton.git

Generate a local.properties for IconButton:

android update project -n IconButton --path IconButton/IconButton

Then reference the library from your own project.properties:

android.library.reference.1=IconButton/IconButton

If you already have library references, change the 1 to the appropriate number.

Usage

In your layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/your.project.package"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

<!-- ... -->

  <com.phillipcalvin.iconbutton.IconButton
      android:id="@+id/search"
      android:drawableLeft="@drawable/action_search"
      android:text="@string/search"
      app:iconPadding="10dp" />

The use of app:iconPadding is optional. It allows you to add padding between the drawable and your text.

Change the text your.project.package to your own project's package. You don't have to use LinearLayout, but you do need to make sure to define the namespace definition (xmlns:app="http://schemas.android.com/apk/res/your.project.package") appears in the root element.

You can assign either a drawableLeft or a drawableRight to the IconButton.

Preview of icon button in several different configurations

Caveats

IconButton only supports one drawable on the left or right. I'll absolutely accept patches that improve its handling of multiple drawables.

Contributors

Special thanks to:

  • @msdx for significant contributions around Android Studio and Gradle support.
  • @kaushikgopal for adding left and right drawable support

License

Copyright (c) 2012-2015 Phil Calvin and contributors.

Licensed under the Apache License, Version 2.0

Contains modified source from ParcelHelper, also under the Apache License.

iconbutton's People

Contributors

johnjohndoe avatar msdx avatar pnc avatar

Watchers

 avatar  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.