Android 背景色透明时,导航栏后面有半透明方块
Android Navigation Bar has half transparant square behind it when making background color transparant
我有一个项目,我正在为其做一个透明的底部导航栏,只有图标是可见的。
我从 Android Studio 中获取了默认的底部导航 Activity 项目,并使导航栏的背景变得透明:
android:background="@android:color/transparent"
现在有一个半透明的正方形,左右填充 8dp 穿过图标(顶部填充出现 16dp?)...在 Nexus 5X 上图像似乎倾斜?任何想法如何删除它?
银河 S7:
连结 5X:
这里是完整的xml代码供参考:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_red_dark"
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="@android:color/transparent"
app:itemIconTint="@android:color/black"
app:itemTextColor="@android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
所以事实证明,将以下属性添加到 XML 内的 <BottomNavigationView />
可以解决问题:
app:elevation="0dp"
(只是把评论里的答案变成常规答案)
我有一个项目,我正在为其做一个透明的底部导航栏,只有图标是可见的。
我从 Android Studio 中获取了默认的底部导航 Activity 项目,并使导航栏的背景变得透明:
android:background="@android:color/transparent"
现在有一个半透明的正方形,左右填充 8dp 穿过图标(顶部填充出现 16dp?)...在 Nexus 5X 上图像似乎倾斜?任何想法如何删除它?
银河 S7:
连结 5X:
这里是完整的xml代码供参考:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_red_dark"
android:paddingTop="?attr/actionBarSize">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="@android:color/transparent"
app:itemIconTint="@android:color/black"
app:itemTextColor="@android:color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
所以事实证明,将以下属性添加到 XML 内的 <BottomNavigationView />
可以解决问题:
app:elevation="0dp"
(只是把评论里的答案变成常规答案)