#RippleButton Widget

March 17, 2015 ยท View on GitHub

Inherits from android.widget.Button but allows you to customize the style easily in differents ways.

Android Lollipop vs Android Jelly Bean

LollipopJellyBean

##Usage

###Layout

AttributeTypeDescription
app:buttonColorcolorThe color of the button.
app:rippleColorcolorThe color of the ripple effect in v21, in previous versions is the color of the button while pressed.

###Style

AttributeTypeDescription
android:colorButtonNormalcolorOnly in v21. The color of the button.
android:colorControlHighlightcolorOnly in v21. The color of the ripple effect in v21
colorButtonNormalcolorNot in v21. The color of the RippleButton.
colorControlHighlightcolorNot in v21. The color of the ripple effect in RippleButton

:paperclip: In version 21 android:colorButtonNormal and android:colorControlHighlight also change the color of the android ImageButton.

###Java

MethodDescription
setButtonColor(int color)The color of the button.
setRippleColor(int color)The color of the ripple effect in v21, in previous versions is the color of the button while pressed.
setColors(int buttonColor, int rippleColor)The color of the button and the ripple effect in v21, in previous versions is the color of the button while pressed.

##Examples From java


	<!--xml-->
    <com.xgc1986.ripplebutton.widget.RippleButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/rippleButton"
        android:text="Click me!"/>

	//java
	int buttonColor = 0xff33b5e5; //holo_blue_light
	int rippleColor = 0x80ffffff; //transparent white
	final RippleButton rb = (RippleButton)findViewById(R.id.rippleButton);
	rb.setColors(colors[1], colors[2]);

From xml


	<!--xml-->
    <com.xgc1986.ripplebutton.widget.RippleButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/rippleButton"
        android:text="Click me!"
        app:rippleColor="#ff33b5e5"
        app:buttonColor="#80ffffff"
        app:/>

Modifying the theme:


	<!-- drawable/style.xml -->
	<!--xml-->
    <style name="AppTheme" parent="android:Theme.Material">
    	<!-- This also affects to android.widget.Button -->
    	<item name="android:colorControlHighlight">#ff33b5e5</item>
        <item name="android:colorButtonNormal">#80ffffff</item>

        <!-- for Jellybean & Kitkat -->
        <!-- This not affect to android.widget.Button -->
        <item name="colorControlHighlight">#ff33b5e5</item>
        <item name="colorButtonNormal">#80ffffff</item>
    </style>

And modifying a style:


	<!-- drawable/style.xml -->
	<!--xml-->
    <style name="AppTheme.Widget.CustomButton" parent="android:Widget.Material.Button">
    	<!-- This also affects to android.widget.Button -->
    	<item name="android:colorControlHighlight">#ff33b5e5</item>
        <item name="android:colorButtonNormal">#80ffffff</item>

        <!-- for Jellybean & Kitkat -->
        <!-- This not affect to android.widget.Button -->
        <item name="colorControlHighlight">#ff33b5e5</item>
        <item name="colorButtonNormal">#80ffffff</item>
    </style>

	<!-- layout -->
	<!--xml-->
    <com.xgc1986.ripplebutton.widget.RippleButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/rippleButton"
        android:text="Click me!"
        android:theme="@style/AppTheme.Widget.CustomButton"/>

Next: RippleImageButton Widget
Prev: README