I've been struggling with this for too long. I created a new Android project with a basic Activity, which comes with a button on a Fragment. My layout looks like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:clipToPadding="false"
android:padding="20dp"
tools:context=".FirstFragment">
<TextView
android:id="@+id/button_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/buttonback"
android:elevation="10dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:text="Text"
android:textColor="@color/black"
android:translationZ="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_other"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:background="@drawable/buttonback"
android:elevation="10dp"
android:text="Button"
android:textColor="@color/black"
android:translationZ="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/button_first" />
</androidx.constraintlayout.widget.ConstraintLayout>
And whatever I try the button drop shadow never changes. Elevation, TranslationZ, changing themes...always just a slightly visible outline around the button. I've tried everything posted on SO, like this popular post, and nothing works or alters the drop shadow. It seems like Google is FORCING buttons to not have drop shadows because textView drop shadows DO work. Here are 2 views a textview and a button with the same attributes:
The textview is on top, and has the drop shadow I want. So what's the trick? How can I get the same drop shadow on a button? BTW, when I press the button is does appear to have a drop shadow, but I want the button to have the drop shadow when NOT pressed.
PS. Annoyingly the button drop shadow appears in the layout design editor...but not when compiled and running on a device.