[英]Transparent toolbar with drawer layout
Currently, I have a transparent toolbar with drawerlayout. 目前,我有一个带有drawerlayout的透明工具栏。 It is positioned in a framelayout so the drawerlayout is overlapped by the toolbar but I want it to be underneath. 它位于framelayout中,因此drawerlayoutout与工具栏重叠,但我希望它在下面。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
<!-- Listview to display slider menu -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:background="@color/list_background"/>
</android.support.v4.widget.DrawerLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/tb_background"
app:theme="@style/TransparentToolbar"
app:titleTextAppearance="@style/Toolbar.TitleText"
>
</android.support.v7.widget.Toolbar>
</FrameLayout>
How can I make it so transparent toolbar does not overlap drawerlayout? 如何使透明工具栏不与drawerlayout重叠呢?
very first of all you don't need extra frame layout for your drawer layout. 首先,您的抽屉布局不需要额外的框架布局。 Just match your layout as shown below. 只需匹配您的布局,如下所示。
Instead using list view you can use new support navigation view for navigation menu as it saves you from extra coding and gives your app an standard looks like other android application. 而是使用列表视图,您可以使用新的支持导航视图导航菜单,因为它可以节省您额外的编码,并为您的应用程序提供标准外观像其他Android应用程序。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- this is the main content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/tb_background"
app:theme="@style/TransparentToolbar"
app:titleTextAppearance="@style/Toolbar.TitleText" />
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="?android:windowContentOverlay" />
</LinearLayout>
<!-- you used here listView -->
<!-- this is the navigation -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/navigation_header"
app:menu="@menu/navigation_menu" />
</android.support.v4.widget.DrawerLayout>
follow the official documentation below: 请遵循以下官方文档:
You need to keep the DrawerLayout
as root layout and inside it use the FrameLayout
with Toolbar
. 您需要将DrawerLayout
保持为根布局,并在其中使用FrameLayout
和Toolbar
。
Something like this: 像这样的东西:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/tb_background"
app:theme="@style/TransparentToolbar"
app:titleTextAppearance="@style/Toolbar.TitleText"
>
</android.support.v7.widget.Toolbar>
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
</FrameLayout>
<!-- Listview to display slider menu -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:background="@color/list_background"/>
</android.support.v4.widget.DrawerLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.