Android 活动布局上的导航抽屉布局
我想创建一个位于主活动顶部的导航抽屉Android 活动布局上的导航抽屉布局,android,Android,我想创建一个位于主活动顶部的导航抽屉 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_pa
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".invento">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<fragment
android:layout_width="@dimen/nav_drawerWidth"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"
android:name="com.invento.defcomm.invento16.navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer" />
我将抽屉放在动作条下面,而不是完全重叠整个活动。请帮我解决这个问题,并指出我做错了什么?谢谢……试试这个
<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">
<!-- The main content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Toolbar instead of ActionBar so the drawer can slide on top -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/abc_action_bar_default_height_material"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextAppearance="?android:attr/textAppearanceMedium" />
<!-- Real content goes here -->
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/drawer" />
为什么不将默认操作栏更改为工具栏呢。这样,您可以将工具栏包含到布局中,并将导航抽屉保持在工具栏顶部 这是我用来添加工具栏的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_actionbar"
style="@style/ToolBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="@dimen/abc_action_bar_default_height_material"/>
</LinearLayout>
我无法在这里显示完整的代码。请看这里@Amit谢谢。上面代码中的所有内容都正常工作,但导航抽屉位于操作栏下方。我想知道如何更正这个问题。请尝试此链接以获取有关材质设计操作栏和导航抽屉的更多信息
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"/>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".invento">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"/>
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<fragment
android:layout_width="@dimen/nav_drawerWidth"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_alignParentTop="true"
app:layout="@layout/fragment_navigation_drawer"
android:name="com.invento.defcomm.invento16.navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer" />
</RelativeLayout>
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
mToolbar.setLogo(getResources().getDrawable(R.drawable.ic_launcher)); // Your Logo
mToolbar.setTitle("Title"); // Your Title
setSupportActionBar(mToolbar);