简体   繁体   中英

Activity transparent background of home screen not last activity

I'm launching an Activity from the android.intent.action.CALL intent. I'd like to show a layout similar to dialog with progress with transparent background (while i do processing before handing over to native dialer). But behind background that is visible should be the home screen.

At the moment is the activity loads ok and the background outside of the desired loading dialog is transparent but instead of the home screen in the background the last application screen/activity is displayed.

How can I force the background behind my transparent to be the home screen?

In order to do so, just set the android theme in your manifest file to 'Theme.Wallpaper'

ie: <activity android:theme="@android:style/Theme.Wallpaper" />

Also make sure you set a transparent background for your activity. For example, I have defined a translucent black color that I use as background for my activity:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="translucent_black">#CF000000</color>
</resources>

One option (which is highly not recommended) is to kill all other visible processes. This code will take care of it:

import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.Context;
import android.util.Log;

public class Test {
public Test(Context c){
    ActivityManager am = (ActivityManager)c.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> list = am.getRunningAppProcesses();
    for (int i=0; i<list.size(); i++){
        Log.i("apps info", list.get(i).processName +"; PID=" + list.get(i).pid);
        if(list.get(i).importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE){
            android.os.Process.killProcess(list.get(i).pid);
        }
    }
  }
}

Like stated above, this should be avoided. This type of code is best reserved for a Task manager app.

You can't force it to be the Home Screen, but you can grab the current wallpaper and use that as your background.

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    Drawable wallpaper = WallpaperManager.getInstance(this).getDrawable();
    // Set wallpaper to the background of the root view
}

Firstly you shouldnt be altering the activity stack outside of your application, big no no.

Secondly, receiving an broadcast will result in other applications being run in the foreground some of the time (other than the home screen). So you'll have to just accept that will be the case.

You can either display a dialog and use the dialog theme so the background activity, while still there is obscured slightly, or go the other way and just show up a full activity.

use this Theme in your style

<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>

try launchMode="singleInstance" in your manifest;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM