I've created a calculator app, and it works fine, but there's one question - why the background becomes transparent when i close the app by performing home gesture? Here's how it looks:
how to repair this? Thanks, any help appreciated.
Here's the code for this UI, MDC Android:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginBottom="5dp"
android:layout_weight="0"
android:layout_gravity="bottom"
android:orientation="horizontal"
>
<TextView
android:id="@ id/textViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginRight="10dp"
android:layout_marginBottom="1dp"
android:layout_weight="2"
android:text=""
android:textAlignment="textEnd"
android:textSize="50sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginTop="0dp"
android:orientation="horizontal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:id="@ id/buttonDivide"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="/"
android:textAlignment="center"
android:textColor="@color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@ id/buttonMultiply"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="*"
android:textAlignment="center"
android:textColor="@color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@ id/buttonMinus"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="-"
android:textAlignment="center"
android:textColor="@color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@ id/buttonPlus"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text=" "
android:textAlignment="center"
android:textColor="@color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@ id/buttonEquality"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="="
android:textAlignment="center"
android:textColor="@color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom"
>
<Button
android:id="@ id/button7"
android:text="7"
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp" />
<Button
android:id="@ id/button8"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="8"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="@ id/button9"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="9"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom">
<Button
android:id="@ id/button4"
android:text="4"
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp"
/>
<Button
android:id="@ id/button5"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="5"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="@ id/button6"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="6"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom">
<Button
android:id="@ id/button1"
android:text="1"
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp" />
<Button
android:id="@ id/button2"
android:text="2"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="@ id/button3"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="3"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp">
<Button
android:id="@ id/buttonPoint"
android:text="."
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp" />
<Button
android:id="@ id/button0"
android:text="0"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="@ id/buttonDelete"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="DEL"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="@color/md_theme_dark_error"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="60dp"
android:orientation="horizontal"
android:layout_gravity="bottom">
<Button
android:id="@ id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="CLEAR"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="@color/md_theme_dark_error"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I tried disabling the night mode of the system, and apparently in white mode the problem doesn't appear. So the dark mode is causing the problem.
CodePudding user response:
If the dark mode from your phone does that, then you can check res->values->themes->themes.xml(night) and set the default background color.
Another fix is to set the background in the LinearLayout. "android:background="#ffffff"" / "android:background="@color/your_color""
Example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/your_color"
android:padding="16dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginBottom="5dp"
android:layout_weight="0"
android:layout_gravity="bottom"
android:orientation="horizontal"
>
<TextView
android:id="@ id/textViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginRight="10dp"
android:layout_marginBottom="1dp"
android:layout_weight="2"
android:text=""
android:textAlignment="textEnd"
android:textSize="50sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginTop="0dp"
android:orientation="horizontal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:id="@ id/buttonDivide"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="/"
android:textAlignment="center"
android:textColor="@color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@ id/buttonMultiply"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="*"
android:textAlignment="center"
android:textColor="@color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@ id/buttonMinus"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="-"
android:textAlignment="center"
android:textColor="@color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@ id/buttonPlus"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text=" "
android:textAlignment="center"
android:textColor="@color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="@ id/buttonEquality"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="="
android:textAlignment="center"
android:textColor="@color/md_theme_dark_primary"
android:textSize="30sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom"
>
<Button
android:id="@ id/button7"
android:text="7"
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp" />
<Button
android:id="@ id/button8"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="8"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="@ id/button9"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="9"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom">
<Button
android:id="@ id/button4"
android:text="4"
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp"
/>
<Button
android:id="@ id/button5"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="5"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="@ id/button6"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="6"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom">
<Button
android:id="@ id/button1"
android:text="1"
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp" />
<Button
android:id="@ id/button2"
android:text="2"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="@ id/button3"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:text="3"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp">
<Button
android:id="@ id/buttonPoint"
android:text="."
android:layout_marginTop="1dp"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:padding="8dp" />
<Button
android:id="@ id/button0"
android:text="0"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary"
android:gravity="center"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:layout_marginTop="1dp"
android:padding="8dp" />
<Button
android:id="@ id/buttonDelete"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="DEL"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="@color/md_theme_dark_error"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginBottom="60dp"
android:orientation="horizontal"
android:layout_gravity="bottom">
<Button
android:id="@ id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:backgroundTint="@color/md_theme_dark_onPrimary2"
android:gravity="center"
android:text="CLEAR"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="@color/md_theme_dark_error"
android:layout_marginTop="1dp"
android:padding="8dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>