【问题标题】:how to make hamburger menu fully visible如何使汉堡菜单完全可见
【发布时间】:2017-07-11 17:25:03
【问题描述】:
【问题讨论】:
标签:
android
navigation-drawer
【解决方案1】:
您似乎正在使用非常古老的技术来创建Navigation Drawer。它的代码大约有 4 年的历史,似乎 perfect 关于 old version。
仅供参考,以前这种 UI 是使用 DrawerLayout 和 ListView 完成的。但是现在android本身正式引入了滑动面板菜单,引入了一个新的概念,叫做Navigation Drawer,我们结合DrawerLayout和NavigationView来实现想要的输出。
如何让汉堡菜单完全可见?
解决方案:
- 使用
AppCompatActivity 代替Activity 并使用AppCompat 主题来实现您想要的输出。
- 使用
NavigationView 而不是ListView。
这是NavigationView的示例:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Your contents -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/my_navigation_items" />
</android.support.v4.widget.DrawerLayout>
这里有一个很好的教程:Android Sliding Menu using Navigation Drawer
希望对你有帮助~