如何停止将背景颜色添加到 BottomNavigationView
How to stop background colour from being added to BottomNavigationView
我是 android 工作室的新手,如有任何帮助,我们将不胜感激。
出于某种原因,向我的 FrameLayout 添加背景颜色会填充我的 BottomNavigationView 的背景。我不明白为什么会这样,因为我使用 layout_above 标记将我的 FrameLayout 设置在 BottomNavigationView 上方,并为其提供了我的 BottomNavigationView 的 ID。
这是我的 xml 文件,其中包含 FrameLayout 和 BottomNavigationView:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:design="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/bottom_navigation_bar"
android:layout_alignParentTop="true"
android:background="@color/colorPrimaryDark">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bottom_navigation_bar"
android:layout_gravity="bottom"
design:menu="@menu/navigation_menu" />
</android.support.design.widget.CoordinatorLayout>
这是我的菜单 xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_home"
android:title="@string/on_home"
android:icon="@drawable/ic_home"/>
<item
android:id="@+id/action_saved"
android:title="@string/on_saved"
android:icon="@drawable/ic_file_download"/>
<item
android:id="@+id/action_profile"
android:title="@string/on_profile"
android:icon="@drawable/ic_action_user"/>
更改此行
android:layout_above="@id/bottom_navigation_bar"
和
android:layout_above="@+id/bottom_navigation_bar"
希望对您有所帮助。如果这不起作用,请尝试使用以下代码
更改您的 xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:design="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_navigation_bar"
android:layout_alignParentTop="true"
android:background="@color/colorPrimaryDark">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bottom_navigation_bar"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
design:menu="@menu/navigation_menu" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
尝试使用这个 xml
我是 android 工作室的新手,如有任何帮助,我们将不胜感激。
出于某种原因,向我的 FrameLayout 添加背景颜色会填充我的 BottomNavigationView 的背景。我不明白为什么会这样,因为我使用 layout_above 标记将我的 FrameLayout 设置在 BottomNavigationView 上方,并为其提供了我的 BottomNavigationView 的 ID。
这是我的 xml 文件,其中包含 FrameLayout 和 BottomNavigationView:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:design="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/bottom_navigation_bar"
android:layout_alignParentTop="true"
android:background="@color/colorPrimaryDark">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bottom_navigation_bar"
android:layout_gravity="bottom"
design:menu="@menu/navigation_menu" />
</android.support.design.widget.CoordinatorLayout>
这是我的菜单 xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_home"
android:title="@string/on_home"
android:icon="@drawable/ic_home"/>
<item
android:id="@+id/action_saved"
android:title="@string/on_saved"
android:icon="@drawable/ic_file_download"/>
<item
android:id="@+id/action_profile"
android:title="@string/on_profile"
android:icon="@drawable/ic_action_user"/>
更改此行
android:layout_above="@id/bottom_navigation_bar"
和
android:layout_above="@+id/bottom_navigation_bar"
希望对您有所帮助。如果这不起作用,请尝试使用以下代码
更改您的 xml <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:design="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_navigation_bar"
android:layout_alignParentTop="true"
android:background="@color/colorPrimaryDark">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bottom_navigation_bar"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
design:menu="@menu/navigation_menu" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
尝试使用这个 xml