我正在使用 Android Studio 实现一个应用程序,并且创建了一个 Activity 来选择背景。如果我使用我已经实现的导航按钮,一切都会正常,但是如果我在BackgroundActivity中按下系统后退箭头,图像就会变小并且不会覆盖整个屏幕(如下所示)。我尝试在 onResume() 函数中重置背景,然后 invcalidate 但它不起作用。 我把onResume()函数的代码以及背景是如何实现的放在下面 希望问题清楚
<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();
}
我怀疑你没有返回MainActivity,你现在处于选择bg antivity。