Links

GitHub Issues Apache License 2.0 Bintray app-debug.apk (v0.0.3 stable)

Contributors

fennifith

Buttons

git://github.com/fennifith/Buttons.git

Buttons is a library with a large amount of themable styled buttons.

For testing and experimentation purposes, a sample apk can be downloaded here.

Setup

The Gradle dependency is available through jCenter, which is used by default in Android Studio. To add the module to your project, copy this line into the dependencies section of your build.gradle file.

compile 'james.buttons:buttons:0.0.3'

Usage

Adding A Button In XML

To add a button to a layout file in XML, simply add a button like normal, except replace the tag with james.buttons.Button like below.

<james.buttons.Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I\`M SO FANCY, YOU ALREADY KNOW" />

Changing The Background Color

When a Button is created, the default background color is solid black. To change this, add an app:backgroundColor attribute like below.

<james.buttons.Button
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I\'M IN THE FAST LANE FROM L.A. TO TOKYO"
    app:backgroundColor="#FAFAFA"/>

You can also change the color programatically using the Button.setBackgroundColor(int) method like below.

Button button = (Button) findViewById(R.id.button);
button.setBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent));

By default, the button will automatically assign a text color that contrasts the current background when a color is set. To disable that, simply call Button.setBackgroundColor(int, boolean) like below, or call Button.setTextColor(int) with the desired color after the background color has changed.

Button button = (Button) findViewById(R.id.button);
button.setTextColor(R.color.colorPrimary);
button.setBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent), false);

Changing The Text Color

The text color can be changed by using the Button.setTextColor(int) method. In XML, the android:textColor attribute will not work. You must use app:textColor instead.

Changing The Button Style

To change the button type use the app:backgroundType attribute like below. There are currently four different styles: solid, outline, round, and roundOutline.

<james.buttons.Button
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I LIKE TRAINS"
    app:backgroundStyle="outline"/>

The style can also be changed programatically by using the Button.setBackgroundType(Button.Type) or Button.setBackgroundType(Button.Type, boolean) method like below.

Button button = (Button) findViewById(R.id.button);
button.setBackgroundType(Button.Type.OUTLINE);

Enabling/Disabling Ripples

Ripple animations will be visible by default (with the exception of outlined buttons - see issue #6). To disable them, use the Button.setRippleEnabled(boolean) method, or add app:ripplesEnabled="false" in the layout file. The ripple color is determined automatically based on the current text color and button style.

Last updated: 2018-04-25 23:04:32 +0000

This site may do shady things with cookies and stuff because it's evil. Please don't read my privacy policy. close