Android Material 设计中的 ImageButton 没有显示阴影
Android ImageButton in Material Design shows no shadow
我无法在布局的任何组件下显示 material 设计阴影,我不明白为什么。
Android 最小 sdk 是 21,<style name="AppTheme" parent="android:Theme.Material.Light">
,例如,如果我添加一个 FabButton,它的阴影会根据其高度参数正常工作。但不适用于我的 ImageButton 或任何其他组件。
它的布局是:
<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" />
我也已经尝试设置不同于@null 的背景,没有任何变化,没有阴影。这是怎么回事?我在布局组件上有哪种高度阴影?
尝试删除 android:background="@null"
而不是仅更改。当 ImageView 的 BG 为 null 时,您将看不到阴影。另见 this 答案。
尝试从您的图像按钮中删除 android:background="@null"
<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" />
我无法在布局的任何组件下显示 material 设计阴影,我不明白为什么。
Android 最小 sdk 是 21,<style name="AppTheme" parent="android:Theme.Material.Light">
,例如,如果我添加一个 FabButton,它的阴影会根据其高度参数正常工作。但不适用于我的 ImageButton 或任何其他组件。
它的布局是:
<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" />
我也已经尝试设置不同于@null 的背景,没有任何变化,没有阴影。这是怎么回事?我在布局组件上有哪种高度阴影?
尝试删除 android:background="@null"
而不是仅更改。当 ImageView 的 BG 为 null 时,您将看不到阴影。另见 this 答案。
尝试从您的图像按钮中删除 android:background="@null"
<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" />