如何在浏览其他应用程序时将图像保留在屏幕上

How to keep the image on the screen while browsing through other applications

我正在申请在屏幕上创建图像并在我的 phone 上创建应用程序,并且仍然正常使用 phone 功能。我想用 Overlay 和 Activity translucent 但我不能使用 phone 功能。我错了还是我错过了什么?任何人都可以帮我吗? 感谢阅读。

我认为您正在寻找所有应用程序顶部的 "facebook-chat-head" 图标。对吧?

那就是这里,

Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications. Very few applications should use this permission; these windows are intended for system-level interaction with the user.

Constant Value: "android.permission.SYSTEM_ALERT_WINDOW"

here

示例代码:

public class ChatHeadService extends Service {

  private WindowManager windowManager;
  private ImageView chatHead;

  @Override public IBinder onBind(Intent intent) {
    // Not used
    return null;
  }

  @Override public void onCreate() {
    super.onCreate();

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    chatHead = new ImageView(this);
    chatHead.setImageResource(R.drawable.android_head);

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT);

    params.gravity = Gravity.TOP | Gravity.LEFT;
    params.x = 0;
    params.y = 100;

    windowManager.addView(chatHead, params);
  }

  @Override
  public void onDestroy() {
    super.onDestroy();
    if (chatHead != null) windowManager.removeView(chatHead);
  }
}

Don't forget to start the service somehow:

startService(new Intent(context, ChatHeadService.class));

完整代码here:

请查看此线程:chat head related techniques