如何使抽屉布局位于操作栏/工具栏下方?我正在使用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作为非顶级视图?
android toolbar android-support-library navigation-drawer drawerlayout
我使用@GunnarKarlsson在此处显示的以下代码获取透明的Actionbar:透明操作栏:自定义tabcolor
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));
Run Code Online (Sandbox Code Playgroud)
它的工作方式非常完美,除了它如何影响导航抽屉.它不是直接滑动到动作栏下方,而是滑过它.下面是两张图片来澄清我的意思.我试图弄清楚如何从第一张图像中实现导航抽屉的放置,但保留第二张图像上显示的透明度.有没有人遇到过类似的问题?


transparency android titlebar android-actionbar navigation-drawer
我最近在Android Studio中打开了一个项目,并选择了一个导航抽屉活动.它创建了导航抽屉,除了它以我不喜欢的方式显示 - 导航抽屉显示在标题栏的顶部,例如:

相反,我希望它像:

在这个"正确"的示例中,标题栏 - "主页"与关闭箭头一起显示,同时导航抽屉打开.
文件来源:
app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.avi12.soundcloudinstantdownloader.MainActivity"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.avi12.soundcloudinstantdownloader.MainActivity"
tools:showIn="@layout/app_bar_main">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="What this app can download:"/>
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView"
android:layout_below="@+id/textView"
android:layout_marginLeft="17dp"
android:layout_marginStart="17dp"
android:text="Single tracks"/>
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView8"
android:layout_alignStart="@+id/textView8"
android:layout_below="@+id/textView8"
android:text="Playlists, a.k.a albums"/>
<TextView
android:id="@+id/textView10" …Run Code Online (Sandbox Code Playgroud)