Search code examples
androidbuttonmaterial-designflat

Material Design Button without Shadow


I recently started android development and I am struggling a bit. I read different articles and tutorials on creating drawables etc.


Current Situation

I have created the following buttons:

Social Login Buttons

Using the following code:

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/login_btn_facebook"
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:drawableStart="@drawable/ic_btn_login_facebook"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:text="Continue with Facebook"
        android:textColor="#fff"
        app:backgroundTint="#3b5998"/>

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/login_btn_google"
        android:layout_width="fill_parent"
        android:layout_height="60dp"
        android:drawableStart="@drawable/ic_btn_login_google"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:text="Continue with Google"
        app:backgroundTint="#ffffff" />

Now I actually just need a minor change:
I do not want to have the elevation. I want the buttons to be "flat", and only show the shadow effect when clicked.

Is there a simple way to do this?

Thank you already!


UPDATE:
I need to target API Level 19 as a minimum SDK version.


Solution

  • You have two alternatives to do that:

    1. By adding an XML attribute to your XML Button:

    Try this: android:stateListAnimator="@null"

    1. By adding another XML attribute, if the previous alternative has not worked:

    Add this style="?android:attr/borderlessButtonStyle" to your XML Button according this.

    enter image description here

    Let me know if it doesn't work!