0

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?

Anil
  • 1,027
  • 1
  • 9
  • 24
Sandor Mezil
  • 373
  • 1
  • 3
  • 16
  • 1
    try this [https://stackoverflow.com/questions/15333529/how-to-provide-shadow-to-button](https://stackoverflow.com/questions/15333529/how-to-provide-shadow-to-button) – PCGALI ANDROID Aug 01 '17 at 05:32

2 Answers2

1

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.

Dmitriy Miyai
  • 620
  • 6
  • 12
  • Thank you! That did the trick, and adding `android:background="@android:drawable/dialog_holo_light_frame"` has a much more beautiful visual effect. (thank you @pcgali-android) – Sandor Mezil Aug 01 '17 at 06:46
1

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" />
AskNilesh
  • 58,437
  • 15
  • 99
  • 129