【问题标题】:Toolbar title is being drawn behind status bar工具栏标题正在绘制在状态栏后面
【发布时间】:2017-02-07 12:19:21
【问题描述】:

我遇到了CoordinatorLayoutAppBarLayot 的问题。我的样式资源中有windowTranslucentStatus = trueActivity 的顶部布局(CoordinatorLayout)中有android:fitsSystemWindows="true"。但是有一个问题:当我向下滚动时,Toolbar 上升(没关系),而Toolbar 标题通过StatusBar 保持可见。

开始状态

结束状态。在这里你可以看到下面的文字StatusBar

XML:

<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:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.wldev.lawbite.enquerie.ChooseRecepientActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark"
            app:title="@string/activity_chose_recipient_title"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardCornerRadius="0dp"
            app:cardElevation="0dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:alpha="0.9"
                    android:contentDescription="@string/search_icon_cd"
                    android:padding="14dp"
                    android:src="@drawable/ic_search"
                    android:tint="@color/black" />

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp"
                    android:layout_marginTop="16dp"
                    android:background="@null"
                    android:hint="@string/find_by_name_hint"
                    android:textColor="@color/black"
                    android:textColorHint="@color/gray_50_transparent"
                    android:textSize="14sp" />
            </LinearLayout>
        </android.support.v7.widget.CardView>

    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:paddingTop="2dp"
        android:visibility="visible"
        app:dataSource="@{recipients}"
        app:layoutManager="LinearLayoutManager"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

还有一件事

如果我在 CoordinatorLayout 周围加上一些布局,一切都会好起来的,Toolbar 会正确隐藏。

【问题讨论】:

  • 尝试删除这个:app:layout_scrollFlags="scroll|enterAlways"
  • 或者确保活动不是半透明的
  • @BasuSingh 删除 scrollFlags 删除工具栏的滚动(我希望它隐藏)。活动在主题中有windowTranslucentStatus true,仅此而已。
  • 试着把 WindowTranslucentStatue=false;
  • 这样就可以了。因为,WindowTranslucentStatue=true 将使您的应用在状态栏后面绘制。

标签: android android-layout android-coordinatorlayout


【解决方案1】:

将此添加到您的 AppBarLayout

android:fitsSystemWindows="true

而且,它会起作用的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 2015-01-10
    • 2016-01-20
    相关资源
    最近更新 更多