【问题标题】:First item in RecyclerView does not go under status barRecyclerView 中的第一项不在状态栏下
【发布时间】:2017-10-04 10:48:51
【问题描述】:

我有以下布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    android:fitsSystemWindows="true"
    tools:context="com.skillberg.weather.ui.activity.MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/weather_rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:fitsSystemWindows="true" />


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

和风格:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBarOverlay">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>

我希望 RecyclerView 中的第一项显示在状态栏(如工具栏)下,但它没有显示在那里:

不过,RecyclerView 本身在状态栏下绘制,但似乎有一些顶部填充,其高度 = 状态栏高度:

如何解决?

【问题讨论】:

  • 从 RecyclerView 中移除 android:fitsSystemWindows="true"
  • @VinayakB 如果我删除它,它会位于状态栏下方:i.imgur.com/RFySVcx.jpg
  • 你为什么不在你的风格中添加 true

标签: android android-recyclerview material-design android-statusbar


【解决方案1】:

使用windowTranslucentStatus 扩展您的AppTheme,例如

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:windowTranslucentStatus">true</item>
        // other stuff
</style>

这将使StatusBar 变得透明。你不需要使用android:fitsSystemWindows

【讨论】:

  • 还有一个问题:有没有办法去除灰色调:i.imgur.com/UuBi251.png?我试过谷歌,但没有任何帮助。
  • 哪种灰色调?
  • @arts777 该主题有不同的答案,但没有一个能够可靠地工作。您可能想为此提出一个新问题。
【解决方案2】:

在您的 CoordinatorLayout 中,将此 android:fitsSystemWindows="true" 更改为 false

【讨论】:

    【解决方案3】:

    您缺少与 CoordinatorLayout 配合使用的行为。 只需将其添加到您的 RecyclerView 如下:

    <android.support.v7.widget.RecyclerView
        android:id="@+id/weather_rv"
        app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:fitsSystemWindows="true" />
    

    【讨论】:

    • 没有改变:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多