Mihail Malahov
Mihail Malahov

Reputation: 11

How to set drawable on screen when app is in background?

Now I have this blue screen when app is in background, I want to change this blue screen to another drawable screen. How can I do this?enter image description here

I use this:

 @Override
protected void onPause() {
    super.onPause();
    mBinding.getRoot().setBackground(ContextCompat.getDrawable(this, R.drawable.checkmark));
    mBinding.fragmentContainer.setVisibility(View.GONE);
}

and my layout:

<?xml version="1.0" encoding="utf-8"?>
<data></data>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/authorized"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/green" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white" />

    </RelativeLayout>

    <LinearLayout
        android:id="@+id/sliding_up_panel"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/authorized"
        android:background="@android:color/transparent"
        android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        android:visibility="gone">

        <FrameLayout
            android:id="@+id/activity_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent" />

    </LinearLayout>

</FrameLayout>

I just have white screen when app is in background.

Upvotes: 1

Views: 130

Answers (1)

Ganesh MB
Ganesh MB

Reputation: 1189

Yeap Its possible with onPause()

 @Override
protected void onPause() {
    super.onPause();
    containerRoot.setBackgroundColor(ContextCompat.getColor(this , R.color.blue));
    containerBody.setVisibility(View.GONE);
}

Step 1:

Set BackgroundColor in your root layout

Step 2:

Set Visibility to GONE in your body layout

EDIT

containerRoot.setBackground(ContextCompat.getDrawable(this, R.drawable.my_drawable));

Upvotes: 1

Related Questions