0

我是android studio的新手,任何帮助将不胜感激。

出于某种原因,向我的 FrameLayout 添加背景颜色正在填充我的 BottomNavigationView 的背景。我不明白为什么会发生这种情况,因为我使用 layout_above 标签将 FrameLayout 设置在 BottomNavigationView 上方,并为其提供了我的 BottomNavigationView 的 ID。

这是我的包含 FrameLayout 和 BottomNavigationView 的 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">

 <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"/>

4

1 回答 1

0

更改此行

 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

于 2017-02-21T12:50:33.733 回答