我的问题很简单。
我创建了一个抽屉导航 Activity 。当抽屉打开时,它是这样的:
我希望抽屉位于工具栏下方,所以我会看到“后退箭头”,如下所示:
从我见过的其他项目来看,我认为可以通过使用“FrameLayout”来完成。 “nav_header”布局包含一个 FrameLayout,它覆盖整个屏幕但工具栏。我只是不知道到底该怎么做:
附注 如何设置抽屉导航的宽度? 我想要它更窄......
最佳答案
关于抽屉导航到工具栏的定位,正如@Stankovitch 所提到的帖子中所解释的那样, - 这只是 Activity XML 中 UI 元素的顺序问题
我敢打赌,你现在有这样的东西:
<android.support.v4.widget.DrawerLayout>
<RelativeLayout>
<android.support.v7.widget.Toolbar/>
<FrameLayout/> <!-- Screen content-->
</RelativeLayout>
<android.support.design.widget.NavigationView/> <!-- drawer content-->
</android.support.v4.widget.DrawerLayout>
所以你需要将其重写为:
<RelativeLayout>
<android.support.v7.widget.Toolbar/>
<android.support.v4.widget.DrawerLayout>
<FrameLayout/> <!-- Screen content-->
<android.support.design.widget.NavigationView/> <!-- drawer content -->
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
关于宽度 - 只需明确指定所需的宽度:
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
上面的抽屉宽度为 100dp。
关于android - 设置工具栏下的抽屉导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34116245/