【发布时间】:2016-12-02 20:27:41
【问题描述】:
我在网上找到了一个半透明的系统栏、一个 CoordinatorLayout、一个 AppBarLayout 和一个工具栏。使用 NestedScrollView 滚动会将工具栏移动到顶部,系统栏下方,但会留下一些像素。这看起来很丑:
所以这里有一些细节:
- 编译SdkVersion 23
- buildToolsVersion "23.0.3"
- minSdkVersion 21
- targetSdkVersion 23
- 'com.android.support:appcompat-v7:23.4.0'
- 'com.android.support:design:23.4.0'
风格:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@android:color/transparent</item>
<item name="colorPrimaryDark">@android:color/transparent</item>
<item name="colorAccent">#22DDAA</item>
<item name="colorControlNormal">#ffffff</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowTranslucentStatus">true</item>
<!--<item name="android:windowTranslucentNavigation">true</item>-->
<!--<item name="android:fitsSystemWindows">false</item>-->
</style>
布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/gradient"/>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/activity_password_forgot_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:titleTextAppearance="@style/actionbar_title"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
style="@style/text_white_strong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lorem ipsum dolor..."/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
顺便说一句:我需要将这个 RelativeLayout / ImageView 组合用于背景中的大图像,该图像也应该在系统栏下可见。对于这个问题,我只使用渐变...
好的,我将布局修改为:
<android.support.design.widget.CoordinatorLayout>
<RelativeLayout>
<ImageView/>
</RelativeLayout>
<android.support.design.widget.AppBarLayout>
<android.support.v7.widget.Toolbar/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView>
<LinearLayout>
<TextView/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
现在看起来像这样:
然后我尝试了 android:fitsSystemWindows="true" 的许多变体,但我无法在该系统栏下方获得该工具栏(系统栏没有变灰...)
【问题讨论】:
-
CoordinatorLayout 应该是父视图。当您将 RelativeLayout/ImageView 作为 CL 的子级时,您可以获得相同的结果。
-
android:fitsSystemWindows="true" 在工具栏和 AppBarLayout 上。是的,请删除RelativeLayout
标签: android themes android-toolbar android-coordinatorlayout coordinator-layout