0

Пишу приложение "Погода". Фотография для фона меняется программно, в зависимости от погодных условий на данный момент. Проблема в том, что экспериментирую с CoordinatorLayout и не могу поменять фон для всего экрана в целом. Либо фон меняется в CoordinatorLayout, а в остальной части экрана остаётся без изменений. Либо, наоборот, Фон экрана изменяется везде, кроме CoordinatorLayout. Подскажите, пожалуйста, как поменять фон на всём экране, включая CoordinatorLayout и RecyclerView, который в него помещён?

P.S.: ImageView с id background - и есть фон для экрана, который изменяется программно

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:background="#00BFFF">

    <ImageView
        android:id="@+id/background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        tools:src="@mipmap/ic_launcher_round" />

    <TextView
        android:id="@+id/textViewLocation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:textSize="30sp"
        tools:text="fsdfsfdsfsdf" />

    <ImageView
        android:id="@+id/weatherIcon"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_below="@id/textViewLocation"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        tools:src="@mipmap/ic_launcher_round" />

    <RelativeLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/weatherIcon">

        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/coordinatorLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/main.appbar"
                android:layout_width="match_parent"
                android:layout_height="250dp">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/main.collapsing"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginEnd="64dp"
                    app:expandedTitleMarginStart="32dp"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed">

                    <TextView
                        android:id="@+id/textViewCurrentTemp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:layout_marginTop="10dp"
                        android:textSize="90sp"
                        tools:text="fsdfsfdsfsdf"
                        app:layout_collapseMode="parallax" />

                    <TextView
                        android:id="@+id/textViewDate"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="120dp"
                        android:textSize="20sp"/>

                    <TextView
                        android:id="@+id/textViewSunrise"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="150dp"
                        android:textSize="20sp"/>

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

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

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/scrollView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="50dp"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <LinearLayout
                    android:id="@+id/linLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" />
            </android.support.v4.widget.NestedScrollView>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="8dp"
                android:background="@color/colorAccent"
                android:elevation="4dp"
                android:minHeight="?android:attr/actionBarSize"
                android:orientation="vertical"
                app:layout_anchor="@id/main.appbar"
                app:layout_anchorGravity="bottom"
                app:layout_collapseMode="pin">

                <View
                    android:id="@+id/upperDivider"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#FFFFFF" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/colorPrimary" />

                <View
                    android:id="@+id/lowerDivider"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#FFFFFF" />
            </LinearLayout>

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

    </RelativeLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/textViewLocation">

        <com.pnikosis.materialishprogress.ProgressWheel
            android:id="@+id/progressWheel"
            android:layout_width="@dimen/progress_wheel_size"
            android:layout_height="@dimen/progress_wheel_size"
            android:layout_gravity="center"
            app:matProg_progressIndeterminate="true" />

    </FrameLayout>

</RelativeLayout>

1 ответ 1

1

Попробуйте фон внутренних элементов установить на прозрачный и устанавливать цвет фона, а точнее сам background во внешнем CoordinatorLayout.

1
  • Спасибо! Только я background оставил без изменений, в корневом Layout'е, а фон внутренних элементов, как вы и сказали, сделал прозрачным. И всё сработало. 24 мар 2020 в 11:47

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими пользовательским соглашением, политикой конфиденциальности и политикой о куки

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.