【问题标题】:Navigation view going under toolbar in android导航视图在android的工具栏下
【发布时间】:2018-04-19 10:00:19
【问题描述】:

我正在尝试添加导航视图,但它位于工具栏下方。结果,第一项不可见,并且表示处于关闭状态的导航视图的前三个水平线也未显示。

代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

   <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

activity_main_drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_home"
            android:icon="@drawable/ic_action_home"
            android:title="Home" />
        <item
            android:id="@+id/nav_profile"
            android:icon="@drawable/ic_action_profile"
            android:title="My Profile" />
        <item
            android:id="@+id/nav_history"
            android:icon="@drawable/ic_action_history"
            android:title="History" />
        <item
            android:id="@+id/nav_payment"
            android:icon="@drawable/ic_action_payment"
            android:title="Payment Methods" />
        <item
            android:id="@+id/nav_contact"
            android:icon="@drawable/ic_action_contact"
            android:title="Contact" />
        <item
            android:id="@+id/nav_about"
            android:icon="@drawable/ic_action_about"
            android:title="About" />
        <item
            android:id="@+id/nav_logout"
            android:icon="@drawable/ic_action_log_out"
            android:title="Logout" />
    </group>


</menu>

nav_header_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:text="Vitalia"
        android:id="@+id/navHeaderTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</android.support.constraint.ConstraintLayout>

已尝试的解决方案:

我尝试在导航视图中添加android:layout_marginTop="@dimen/abc_action_bar_default_height_material",但结果为()

如何解决?

【问题讨论】:

  • 请您的 app_bar_main.xml 布局代码。
  • android:fitsSystemWindows="true" 这只会传递给您的 app_bar_main.xml 布局。
  • @AnkushBist 如果我将删除 app_bar_main.xml 比也存在同样的问题。
  • 不,我不是要删除布局,我想知道其中的代码。因为这使您可以显示其他布局元素
  • android:fitsSystemWindows="true" 从您的抽屉布局中删除此代码。

标签: android navigation navigation-drawer


【解决方案1】:

试试这个

<android.support.v4.widget.DrawerLayout
    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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/container_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:orientation="vertical">

            <android.support.v7.widget.Toolbar
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/ColorPrimary"
                android:minHeight="?attr/actionBarSize"
                android:theme="@style/ToolbarColoredBackArrow"  
                app:titleTextColor="@color/White">

            </android.support.v7.widget.Toolbar>


        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/container_toolbar">

            <FrameLayout
                android:id="@+id/container_body"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"/>
        </LinearLayout>


    </RelativeLayout>

    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:name="com.fr.fleetrover.fragment.FragmentDrawer"
        android:layout_width="260dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        tools:layout="@layout/fragment_navigation_drawer">
    </fragment>

</android.support.v4.widget.DrawerLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 1970-01-01
    相关资源
    最近更新 更多