Borderless Button on Pre-Lollipop with Support Library

Borderless Button works on both Post and Pre Lollipop version with Support Library but there's a small difference between their onPressed color.

Pre-Lollipop: By default onPressed color is same as default Button color set using colorButtonNormal.

Lollipop: By default onPressed color is light grey, which is ideal.

You can make a Borderless Button like this:

<Button  
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Name"
    style="@style/Widget.AppCompat.Button.Borderless"/>

Now If you want to have the same onPressed color on all versions then you can set colorControlHighlight in a new theme and set that theme on Button.

<Button  
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Name"
        android:theme="@style/BorderlessButton"
        style="@style/Widget.AppCompat.Button.Borderless"/>

And theme in your style:

<style name="BorderlessButton" parent="Theme.AppCompat.Light">
      <item name="colorControlHighlight">YOUR COLOR</item>
</style>

Updated: You can use android:theme attribute for a View since Android 5.0 Lollipop and AppCompat v22.1.0 (and higher).


Adding style="?borderlessButtonStyle" to the Button worked fine for me.