【问题标题】:How to set drawable on screen when app is in background?如何在应用程序处于后台时在屏幕上设置可绘制对象?
【发布时间】:2022-12-23 22:00:05
【问题描述】:

现在当应用程序处于后台时我有这个蓝屏,我想将这个蓝屏更改为另一个可绘制屏幕。我该怎么做?enter image description here

我用这个:

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

和我的布局:

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

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

    <View
        android:id="@+id/sb_authorized"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/covr_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/activity_sliding_up_panel"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/sb_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_lockscreen_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent" />

    </LinearLayout>

</FrameLayout>

当应用程序处于后台时,我只有白屏。

【问题讨论】:

    标签: android


    【解决方案1】:

    是的它有可能与onPause()

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

    步骤1:

    在根布局中设置背景颜色

    第2步:

    在您的身体布局中将可见性设置为 GONE

    编辑

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

    【讨论】:

    • 我需要设置可绘制背景,而不是背景颜色,您的解决方案对我不起作用
    • @MihailMalahov 看到我的编辑,没问题使用 R.drawable.name 而不是 R.color.name
    • 当我听从你的建议时,我只有白色背景
    • 你能用代码示例更新你的问题吗
    猜你喜欢
    • 1970-01-01
    • 2021-06-15
    • 1970-01-01
    • 2011-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多