use*_*971 47 android toolbar android-support-library navigation-drawer drawerlayout
如何使抽屉布局位于操作栏/工具栏下方?我正在使用v7:21 app compat库和新的ToolBar视图.
我看到的例子看起来像
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- drawer view -->
<LinearLayout
android:layout_width="304dp"
android:layout_height="match_parent"
android:layout_gravity="left|start">
<!-- drawer content -->
</LinearLayout>
<!-- normal content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The toolbar -->
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<!-- The rest of content view -->
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
但随后工具栏将被抽屉隐藏,这使得动画汉堡图标(如v7.ActionBarDrawerToggle)无用,因为它在抽屉下方不可见,但我确实想使用新的ToolBar视图来更好地支持Material主题.
那么如何实现呢?是否可以将DrawerLayout作为非顶级视图?
小智 95
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The toolbar -->
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- drawer view -->
<LinearLayout
android:layout_width="304dp"
android:layout_height="match_parent"
android:layout_gravity="left|start">
<!-- drawer content -->
</LinearLayout>
<!-- normal content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The rest of content view -->
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
EC8*_*4B4 22
我不认为你在使用自定义时可以 toolbar
但是解决方法是设置top_margin抽屉.(谷歌游戏商店也一样!)
<!-- drawer view -->
<LinearLayout
android:layout_marginTop="?attr/actionBarSize"
...
Run Code Online (Sandbox Code Playgroud)
如果你找到了更好的解决方案,请告诉我;)
| 归档时间: |
|
| 查看次数: |
39608 次 |
| 最近记录: |