【问题标题】:Navigation drawer below Actionbar操作栏下方的导航抽屉
【发布时间】:2014-12-03 21:46:28
【问题描述】:

现在我刚刚在 Android Studio 中使用模板中预配置的 NavigationBar 启动了一个项目。显然它将导航抽屉放在操作栏后面。您发现的许多问题都希望将导航抽屉放在操作栏顶部,我希望它从操作栏下方开始。这是我目前拥有的:

最终想要的情况:

我找到了this的解决方案,但我认为应该有更简单的方法。

【问题讨论】:

标签: android android-fragments navigation-drawer android-4.4-kitkat


【解决方案1】:

将此属性应用于您的根视图组android:layout_marginTop="?android:attr/actionBarSize"。希望这会有所帮助。

【讨论】:

  • 你确定吗?请再看一次我的回答。
  • 快到了!它似乎没有在此页边距顶部显示通知栏。
  • 显然,我很丢脸:在我的风格中,我有这两个属性:true真的
  • 你这是什么意思?布局视图时不考虑状态栏,但状态栏确实考虑了屏幕的总高度
  • 虽然此变通方法有效,但操作栏会变暗,不会受到这些效果的影响。关于如何解决它的任何想法?
【解决方案2】:

试试这个 MainActivity 布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/app_bar"
        android:theme="@style/AppTheme.AppBarOverlay">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="?attr/actionBarSize"
        android:fitsSystemWindows="true">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            tools:showIn="@layout/app_bar_main">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Put your content View here!" />
        </RelativeLayout>
        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            app:headerLayout="@layout/nav_header_main"
            app:menu="@menu/activity_main_drawer" />
    </android.support.v4.widget.DrawerLayout>
</RelativeLayout>

【讨论】:

  • 您好,我正在使用上面的代码,它在 SDK 23 中运行良好,并且在 SDK 19 ActionbarTitle 上执行相同的代码时没有显示.....这是链接:stackoverflow.com/questions/39957481/…
  • 你为什么不直接使用 layout_below 呢?也许我错过了一点?
  • ActionBarTitle 在 SDK19 上不存在。它出现在 SDK21 之后
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-15
相关资源
最近更新 更多