Android导航抽屉和工具栏
请帮助我创建Android导航抽屉和工具栏,android,navigation-drawer,android-toolbar,Android,Navigation Drawer,Android Toolbar,请帮助我创建工具栏,哪些内容将位于@+id/左抽屉?可能吗? 你要找的东西叫做导航抽屉 我建议您访问Android文档 在这种情况下,您的代码将 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="mat
工具栏
,哪些内容将位于@+id/左抽屉
?可能吗?
你要找的东西叫做导航抽屉 我建议您访问Android文档 在这种情况下,您的代码将
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
style="@style/MainTheme.ToolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.astuetz.RobottoRegularTextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="20sp" />
<com.astuetz.RobottoLightTextView
android:id="@+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="@dimen/small_text"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:background="#fff"/>
</android.support.v4.widget.DrawerLayout>
在父线性布局中,工具栏可以放在第一位,抽屉布局可以放在第二位
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
style="@style/MainTheme.ToolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
(...)
</android.support.v7.widget.Toolbar>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="@+id/left_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
(...)
@hata非常接近正确答案。你需要在抽屉布局
之后放置工具栏
,使工具栏
的背景透明,并在@+id/content\U框架
之前创建表单,在抽屉布局
中,哪个高度将是?attr/actionBarSize
,背景颜色与工具栏相同。这是我给你的解决方案
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.kpi.timetable.views.HackyDrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/YOUR_ACTIONBAR_COLOR"/>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<ImageView
android:id="@+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginBottom="0dp"
android:layout_marginTop="0dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/background" />
</com.kpi.timetable.views.HackyDrawerLayout>
<!-- in your MainTheme.ToolBar style set background -->
<!-- color to "@android:color/transparent" or set it here -->
<!-- as android:background="@android:color/transparent" -->
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
style="@style/MainTheme.ToolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.astuetz.RobottoRegularTextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Расписание"
android:textColor="@android:color/white"
android:textSize="20sp" />
<com.astuetz.RobottoLightTextView
android:id="@+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="@dimen/small_text"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</RelativeLayout>
这是一个简单的抽屉实现。看到我上传的照片就发疯。有一个全屏高度菜单(在您的例子中是listView),在滑动之后,它来自左边框,工具栏的内容在它上面。也许工具栏的背景是透明的,但我不知道如何使它的内容在菜单上(
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.kpi.timetable.views.HackyDrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/YOUR_ACTIONBAR_COLOR"/>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<ImageView
android:id="@+id/left_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginBottom="0dp"
android:layout_marginTop="0dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@drawable/background" />
</com.kpi.timetable.views.HackyDrawerLayout>
<!-- in your MainTheme.ToolBar style set background -->
<!-- color to "@android:color/transparent" or set it here -->
<!-- as android:background="@android:color/transparent" -->
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
style="@style/MainTheme.ToolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.astuetz.RobottoRegularTextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Расписание"
android:textColor="@android:color/white"
android:textSize="20sp" />
<com.astuetz.RobottoLightTextView
android:id="@+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="@dimen/small_text"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</RelativeLayout>