【问题标题】:Navigation drawer does not cover my toolbar [duplicate]导航抽屉没有覆盖我的工具栏[重复]
【发布时间】:2017-08-03 17:23:29
【问题描述】:

我是 android 的初学者,我正在尝试不同的东西。我想用视图寻呼机创建一个导航抽屉。但是每当我这样做时,导航抽屉似乎并没有掩盖顶部的工具栏。我尝试了很多不同的东西。这是我使用的教程的链接。

https://androidbelieve.com/navigation-drawer-with-swipe-tabs-using-design-support-library/

Here's a screenshot of my app

这是activity_main

<LinearLayout 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"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:title="Tuition Manager" />

    <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"
        tools:openDrawer="start">

        <FrameLayout
            android:id="@+id/containerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"></FrameLayout>

        <android.support.design.widget.NavigationView xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:layout_marginTop="-24dp"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

这是content_main

<android.support.design.widget.CoordinatorLayout
    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/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.gupta.aayush.tuitionmanager.ContentMainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@drawable/ic_action_add_user" />

</android.support.design.widget.CoordinatorLayout>

请帮忙!

【问题讨论】:

  • 来自标记选项(强调我的)-“寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及 在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:如何创建最小、完整和可验证的示例。"
  • 这种情况下的图片也会很有用
  • @takendarkk 我希望抽屉式导航覆盖整个屏幕的高度。
  • 我希望您发布在您的问题中重现问题所需的最少代码量。
  • @takendarkk 也这样做了!你能帮忙吗?

标签: android android-viewpager toolbar


【解决方案1】:

将activity_main.xml的xml布局改为

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/drawerLayout"
    >
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

        <FrameLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/containerView">
        </FrameLayout>

        <android.support.design.widget.NavigationView
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:id="@+id/shitstuff"
            app:itemTextColor="@color/black"
            app:menu="@menu/drawermenu"
            android:layout_marginTop="-24dp"
            />

        </LinearLayout>

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

这里我将抽屉布局设置为屏幕的父级,并删除了工具栏以进入下一个布局

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    app:tabGravity="fill"
    app:tabMode="fixed"
    android:background="@color/material_blue_grey_800"
    app:tabIndicatorColor="@color/orange"
    app:tabSelectedTextColor="@color/orange"
    app:tabTextColor="@color/white"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
</android.support.design.widget.TabLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</android.support.v4.view.ViewPager>

【讨论】:

  • 感谢您的回复,但这没有帮助。它进一步弄乱了应用程序。现在导航抽屉位于屏幕底部并且始终显示。 P.S 我会添加一个屏幕截图,但我不知道如何
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-23
  • 2014-10-31
  • 1970-01-01
  • 2019-09-15
相关资源
最近更新 更多