问题描述
我正在尝试在背景下实现AppbarLayout,在AppbarLayout内具有一个静态工具栏,在该工具栏下,我使用的是CollpasingToolBar,该工具栏现在包含一个工具栏,以后应该还包含一个自定义视图,该视图将包含其内容可以根据滚动位置进行缩放,在AppBarLayout的底部,我正在使用TabLayout。 我无法解决的问题是:我希望AppbarLayout Drawable 也会散布在状态栏上,目前我未能实现。 我要附加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"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:windowDrawsSystemBarBackgrounds = "true"
android:statusBarColor="@android:color/transparent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="220dp"
android:background="@drawable/winterscenery"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="180dp"
app:statusBarScrim="@android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
android:fitsSystemWindows="true"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="One" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Two" />
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Three" />
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.nestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/content_text_one" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/content_button" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/content_text_two" />
</LinearLayout>
</android.support.v4.widget.nestedScrollView>
</android.support.design.widget.CoordinatorLayout>
编辑清单文件后:
<activity android:name=".ExitUntilCollapsedActivity" android:theme="@style/JustTryStyle" />
并创建 JustTryStyle 样式:
<style name="JustTryStyle" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>
我的外观如下:
解决方法
您需要添加主题
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
编辑: 按照AndroidManifest中的定义,将这两个添加到您的活动使用的主题中。 如果其他活动也使用此主题,但不应使用透明的导航栏,则需要扩展它并相应地更新AndroidManifest。
编辑2:尝试添加<item name="android:windowTranslucentStatus">true</item>
代替或另外添加
编辑3:还将fitSystemWindow=true
添加到约束布局和应用栏