Having application running above other app

前端 未结 2 807
暗喜
暗喜 2020-12-04 16:58

I want to make an activity that can be opened above ANY app.

Normally, even when the activity is set as dialog, when you switch to my app, you see my app, and in the

2条回答
  •  温柔的废话
    2020-12-04 17:36

    I'm one of the developers of the Tooleap SDK, and we also dealt with this issue. Basically, you don't need to use the SYSTEM_ALERT_WINDOW to display an activity on top of another one. You can just display a regular "shrinked" Activity with a transparent background.

    To make a "shrinked Activity, change the activity window layout params of height and width:

    WindowManager.LayoutParams params = getWindow().getAttributes(); 
    params.x = ...;
    params.y = ...;
    params.width = ...;
    params.height = ...;
    
    this.getWindow().setAttributes(params);
    

    To make a transparent background add to your activity definition in the manifest file:

    android:theme="@android:style/Theme.Translucent"
    

    That way, you can create the illusion of a floating activity:

    Note that only the foreground activity will be resumed, while the background one is paused. But for most apps this shouldn't be an issue.

    Now all that remains is when to launch the floating activity.

    Here is an example of a "floating" calculator app using a regular activity. Note that the activity below the calculator belongs to another app.

    Tooleap Calculator Screenshot

提交回复
热议问题