Android layout 如何确保颜色填充整个底部导航视图?
我现在面临一个问题,我试图在Android layout 如何确保颜色填充整个底部导航视图?,android-layout,bottomnavigationview,Android Layout,Bottomnavigationview,我现在面临一个问题,我试图在app:itemcondground=“@color/purpleBoo” 但颜色似乎并没有填充整个底部导航?为什么这会发生在我身上 我的底部导航代码 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.an
app:itemcondground=“@color/purpleBoo”
但颜色似乎并没有填充整个底部导航?为什么这会发生在我身上
我的底部导航代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/purpleBoo"
app:menu="@menu/bottom_nav_menu"
app:itemIconTint="@color/bottom_nav_color"
app:itemTextColor="@color/bottom_nav_color"/>
</RelativeLayout>
对于您正在使用的当前布局,可以将底部导航面板的宽度最大化为“匹配父项”,因此在“宽度”部分中也可以使用颜色
好的,如果面板周围的空白干扰了你的应用程序的外观,那么你可以改变整个布局的背景,这样看起来会更好。只需在BottomNavigationView中添加androidandroid:background=“@color/purpleBoo”
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/purpleBoo"
app:menu="@menu/bottom_nav_menu"
android:background="@color/purpleBoo"
app:itemIconTint="@color/bottom_nav_color"
app:itemTextColor="@color/bottom_nav_color"/>
</RelativeLayout>
显示父项。。。您在某个地方应用了边距。我没有应用任何边距。您现在是否尝试使用LayoutSpector检查您的布局?您将能够看到空白是什么(或者它来自哪里)。很明显,这里有一些东西在增加空间,所以如果你不知道它来自哪里,我们也不能;但是,一旦你让应用程序运行起来,你可以通过工具->LayoutInspector,连接到你的流程,观察所有窗口元素,直到你找到它的来源。我找不到解决方案?如果你在面前的项目中找不到它,我们怎么做。我们只知道你的XML。我只是复制并粘贴到一个空白的xml中。我替换了@android:color/holo_green_light
的颜色,但该条的宽度超出了预期。因此,您将边距应用于此片段的根(在活动级别),或者活动中的片段容器具有填充/边距,或者您的样式正在应用边距/填充。BottomNavigationView与此无关,图中的片段也与此无关。这是我能帮助你的最大限度了。