工具栏被剪裁在系统栏下方

时间:2016-07-28 12:32:26

标签: android themes android-toolbar android-coordinatorlayout coordinator-layout

在互联网上找到我使用半透明系统栏,带有AppBarLayout和工具栏的CoordinatorLayout。使用NestedScrollView滚动将工具栏移动到顶部,位于系统板下方,但留下了一些像素。这看起来很难看:

scrolled with some left over pixels

所以这里有一些细节:

  • compileSdkVersion 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>

现在看起来像这样:

toolbar too high

然后我尝试了很多变种中的android:fitsSystemWindows =“true”,但是我不能在那个系统组件下面得到那个工具栏(没有系统组变灰......)

1 个答案:

答案 0 :(得分:0)

CoordinatorLayout应该是根布局。就像@алекскей一样,你根本不需要RelativeLayout。你甚至不需要fitSystemWindows。