I created a project in Android Studio implementing view binding and data binding. I don't know why material cards don't show elevation. I already added the declaration android:hardwareAccelerated="true"
in my manifest file.
The material card is inside my fragment which is hosted by my activity... I think I made an error inflating tha fragment inside my activity, is it possible?
here is my fragment .xml file which contains the card:
<?xml version="1.0" encoding="utf-8"?>
<layout 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"
tools:context=".view.auth.LoginFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:checkable="true"
android:clickable="true"
android:elevation="24dp"
android:focusable="true"
app:cardBackgroundColor="@color/cardview_light_background"
app:cardCornerRadius="8dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/margin_sm"
android:orientation="vertical">
<!-- other components -->
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</layout>
As I stated above I already added the declaration hardwareAccelerated=true in my manifest file.
Instead of using android:elevation="@dimen/elevation_lg"
use app:cardElevation
.
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
app:cardElevation="@dimen/elevation_lg"
...>
<!-- Other attributes -->
</com.google.android.material.card.MaterialCardView>