导航抽屉在动作栏下方

13

我刚开始在Android Studio中使用预配置的NavigationBar启动了一个项目。很明显,它会将导航抽屉放在操作栏后面。许多相关问题希望将导航抽屉放在操作栏上方,而我想让它从操作栏下方开始。这是我当前的情况:

当前情况

最终期望的情况如下:

期望情况

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


那些是旧的设计指南,这是更新的指南:http://www.google.com/design/spec/patterns/navigation-drawer.html - tyczj
1
好的,那我应该和我的设计师谈谈这个问题 ;) - Bart Burg
Play Store应用就是这样的:D 我认为你可以通过在你的活动主题样式中添加以下行<item name="android:windowActionBarOverlay">false</item>或更改主题来解决你的问题。 - Ultimo_m
你的解决方案似乎没有起作用,我会在主题中查看。 - Bart Burg
1
@BartBurg,你找到任何解决方案了吗?我也在苦苦挣扎。 - rupesh
显示剩余4条评论
3个回答

24

在您的根ViewGroup上应用此属性 android:layout_marginTop="?android:attr/actionBarSize"。希望这可以帮到您。


快了!似乎无法将通知栏放在这个上边距。 - Bart Burg
显然,这是我的错:在我的样式中,我有这两个属性:<item name="android:windowTranslucentStatus">true</item><item name="android:windowTranslucentNavigation">true</item>。 - Bart Burg
你是什么意思?当布局视图时,状态栏不会被考虑在内,但状态栏会占据屏幕的总高度。 - Biu
1
虽然这个解决方法是可行的,但动作栏被变暗和昏暗了,而它不应该受到这些效果的影响。有什么好的修复方法吗? - ralphgabb
@ralphspoon 我和你提到的问题一样。我在https://dev59.com/AV8d5IYBdhLWcg3wxUjC#26555224找到了解决方案。 - Bruce
显示剩余2条评论

7
尝试使用这个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不显示...... 这是链接:http://stackoverflow.com/questions/39957481/android-navigation-drawer-ui-different-displayed-in-below-sdk-22?noredirect=1#comment67194862_39957481 - Sathish Gadde
为什么不直接使用layout_below呢?也许我错过了什么点? - stdout
ActionBarTitle在SDK19上不存在。它是在SDK21之后出现的。 - Eshan Chattaraj

0

除了Biu的回答之外

还要在您的根视图组中添加此行,以考虑状态栏/导航栏

android:fitsSystemWindows="true"

在这里留下评论,以防有人再次偶然发现这个线程


这并没有回答问题。一旦您拥有足够的声望,您将能够评论任何帖子;相反,提供不需要询问者澄清的答案。- 来自审核 - Abhishek Dutt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接