Sandor Mezil
Sandor Mezil

Reputation: 390

Android ImageButton in Material Design shows no shadow

I can't display the material design shadow under any component of my layout, I can't understand why.

Android minimum sdk is 21, <style name="AppTheme" parent="android:Theme.Material.Light">, and if for example I add a FabButton its shadow works properly according to its elevation parameter. But not for my ImageButton or any other component.

Its layout is:

<ImageButton
    android:id="@+id/btnMain"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/txtTitle"
    android:adjustViewBounds="true"
    android:background="@null"
    android:contentDescription="@string/btnMain_description"
    android:elevation="10dp"
    android:padding="10dp"
    android:scaleType="centerInside"
    android:src="@drawable/btn_yellow"
    app:srcCompat="@android:color/holo_red_light"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp" />

The result with no shadow

I also already tried to set a background different than @null, nothing changes, no shadows. What's going on? Which way my I have my elevation shadow on layout components?

Upvotes: 0

Views: 1706

Answers (2)

AskNilesh
AskNilesh

Reputation: 69671

try this remove android:background="@null" from your image button

   <ImageButton
     android:id="@+id/btnMain"
     android:layout_width="match_parent"
     android:layout_height="100dp"
     android:layout_alignParentStart="true"
     android:layout_below="@+id/txtTitle"
     android:adjustViewBounds="true"
     android:contentDescription="@string/btnMain_description"
     android:elevation="10dp"
     android:padding="10dp"
     android:scaleType="centerInside"
     android:src="@drawable/btn_yellow"
     android:layout_marginLeft="10dp"
     android:layout_marginRight="10dp"
     android:layout_marginTop="10dp" />

Upvotes: 1

Dmitriy Mitiai
Dmitriy Mitiai

Reputation: 1200

Try to remove the android:background="@null" not just change. When ImageView has BG as null, you'll not see the shadow. Also see this answer.

Upvotes: 1

Related Questions