Background probleam in android application

44 Views Asked by At

I'm realizing an application using Android Studio and I've created an Activity to choose the background. Everything works Fine if I use the navigation buttons that I've realized but if I press the system backarrow when I'm in the BackgroundActivity the image became small and doesn't cover all the screen (as showed below). I've tried to reset the background in the onResume() function and then invcalidate but it didn't work. I put below the code of onResume() function and how the background is implemented Hope the problem is clear

<FrameLayout
    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"
    tools:context=".MainActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imgBg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:background="@drawable/background0" />

    <androidx.constraintlayout.widget.ConstraintLayout
...
    @Override
    protected void onResume() {
        super.onResume();

        //Gestione sfondo
        ImageView bg = findViewById(R.id.imgBg);
        bg.setBackground(MainActivity.bgs.getActive());
        bg.invalidate();
    }

When you first open it is like this

Then you select a new background and it opens this

But if you press the backarrow on the left of the system nav bar it happens this

2

There are 2 best solutions below

0
Andersson On BEST ANSWER

I had the same problem, you're using the same drawable for the bg and the small rect of the choice. To solve it create a copy of the drawable or get the resource directly using R.drawable.bg

1
allen On

I suspect you don't go back to MainActivity, you are now at the select bg antivity.