I am trying to place an ImageView over a Button using RelativeLayout. Here is my xml:
I found a solution: simply android:elevation="2dp"
<Button
android:id="@+id/btnAccess"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_gravity="right|center"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView4"
android:background="@drawable/or"
android:layout_alignBottom="@+id/btnRegister"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:elevation="2dp" />
Actually it's much easier to just set the StateListAnimator to @null
<Button
...
android:stateListAnimator="@null" />
Source Android 5.0 android:elevation Works for View, but not Button?
Button is just a TextView with a certain style applied to it, so if you replace Button with TextView you can display an ImageView on top of it. This also works on API < 21.