我创建了一个工具栏
,我设置为我的动作条
和我有它透明的,我的问题是我要它覆盖了内容的其余部分,现在它的行为像一个正常的动作条
在我的的LinearLayout
停止下方。如何让我的工具栏
覆盖我的布局,并有布局充满整个屏幕?
I created a ToolBar
which I set as my ActionBar
and I have it transparent, my question is I want it to overlay the rest of the content, right now it is acting like a normal ActionBar
where my LinearLayout
"stops" below it. How do I make my ToolBar
overlay my layout and have that layout fill the whole screen?
的样式原动作条
就是:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBarOverlay">true</item>
</style>
我的工具栏
:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:minHeight="?attr/actionBarSize"
android:background="@android:color/transparent"/>
和我的工具栏
声明:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setBackgroundResource(Color.TRANSPARENT);
setSupportActionBar(toolbar);
我觉得我失去了一些东西很简单,但搜索我找不到我正在寻找解决方案之后。任何帮助将是AP preciated!
I feel like I'm missing something really simple but after searching I couldn't find the solution I'm looking for. Any help would be appreciated!
编辑: 这是我的完整的XML主要布局:
Here is my full XML Main Layout:
<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"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"/>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Main layout -->
<FrameLayout
android:id="@+id/main_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Nav drawer -->
<fragment
android:id="@+id/fragment_drawer"
android:name="rsay.android.scrollbanner.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="left|start" />
</android.support.v4.widget.DrawerLayout>
你是在正确的轨道上。最简单的方式,你可以做到这一点是使用的FrameLayout
其中内容的ViewGroup
将 match_parent
,而工具栏
是在此之上的ViewGroup
You are on right track. Simplest way you can do it is using FrameLayout
where the content ViewGroup
will match_parent
while the Toolbar
is on top of this ViewGroup
<FrameLayout 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"
tools:context=".MainActivity">
<!-- This can be any child. For sample purposes I assume this layout contains fragments -->
<LinearLayout
android:background="?attr/colorPrimary"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container"
android:orientation="horizontal"/>
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:minHeight="?attr/actionBarSize"
android:background="@android:color/transparent">
</android.support.v7.widget.Toolbar>
</FrameLayout>