我使用Bottom Navigation Bar在Android应用中实施Google's support design library v25.1.0。有没有办法添加阴影效果,就像当前Android原生Google照片应用一样?
答案 0 :(得分:64)
您可以使用简单的视图及其背景在底栏上方绘制自己的阴影:
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="@id/bottom_bar"
android:background="@drawable/shadow"/>
抽拉/ shadow.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#1F000000"
android:endColor="@android:color/transparent"
android:angle="90" />
</shape>
此外,如果使用此方法,则不存在兼容性问题。
答案 1 :(得分:4)
您可以使用高程为任何视图添加阴影
<TextView
android:id="@+id/myview"
...
android:elevation="2dp"
android:background="@drawable/myrect" />
有关详细信息,请参阅this
答案 2 :(得分:2)
对于将CoordinatorLayout与底部导航栏(或BottomAppBar
)配合使用的用户,可以使用以下内容在阴影上方附加阴影:
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/shadow"
app:layout_anchor="@+id/toolbar"
app:layout_anchorGravity="top"/>
很显然,将@+id/toolbar
替换为底部导航栏的ID
答案 3 :(得分:2)
对于使用Material Component的用户,此问题已由require
解决。
从1.1.0-alpha05开始可用:https://github.com/material-components/material-components-android/releases/tag/1.1.0-alpha05
使用com.google.android.material:material:1.1.0-alpha09
设置高程阴影。
此外,请不要忘记在主布局上设置android:elevation="4dp"
,否则阴影将被覆盖。