现在,我刚在Android Studio中启动了一个项目,并在模板中预配置了NavigationBar。显然,它将导航抽屉放在了操作栏的后面。您发现的许多问题都希望导航抽屉位于操作栏的顶部,我希望它从操作栏的下方开始。这是我目前拥有的:
最终期望的情况:
我已经找到了this的解决方案,但我认为应该有一个更简单的方法。
uajslkp61#
将此属性应用到根视图组android:layout_marginTop="?android:attr/actionBarSize"。希望这能有所帮助。
android:layout_marginTop="?android:attr/actionBarSize"
xghobddn2#
请尝试以下主活动布局:
<?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>
hs1ihplo3#
沿着Biu的回答将此行添加到根视图组中,以便考虑状态栏/导航栏
android:fitsSystemWindows="true"
评论,以防有人再次偶然发现此线程
3条答案
按热度按时间uajslkp61#
将此属性应用到根视图组
android:layout_marginTop="?android:attr/actionBarSize"
。希望这能有所帮助。xghobddn2#
请尝试以下主活动布局:
hs1ihplo3#
沿着Biu的回答
将此行添加到根视图组中,以便考虑状态栏/导航栏
评论,以防有人再次偶然发现此线程