Изменение цвета фона Recyclerview приводит к исчезновению панели инструментов. Почему так - PullRequest
0 голосов
/ 06 июня 2019

Я пытаюсь изменить свой фоновый цвет в режиме реселлера, и он отлично работает в android oreo и android Q, я пытался протестировать свое приложение на kitkat и jellybean, но что-то странное происходит.Когда я использую эту строку android:background="@color/backgroundColorRecyclerView", моя строка заголовка исчезает, и происходит нечто подобное Title bar gone

, и когда я удаляю эту строку, все работает нормально, как эта enter image description here

Я часами пытался понять, что ничего не работает.

Вот мой app_bar.xml

    <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>

    <include layout="@layout/content_main" />


</androidx.coordinatorlayout.widget.CoordinatorLayout>

, а вот мой content_main.xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".MainActivity"
    tools:showIn="@layout/app_bar_main">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:paddingTop="60dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/backgroundColorRecyclerView"/>

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/admob_banner_ad_main">
    </com.google.android.gms.ads.AdView>


</RelativeLayout>

1 Ответ

0 голосов
/ 06 июня 2019

Вот что наконец сработало

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".MainActivity"
    tools:showIn="@layout/app_bar_main">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/backgroundColorRecyclerView"/>

    <com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/admob_banner_ad_main">
    </com.google.android.gms.ads.AdView>


</RelativeLayout>
...