Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Create "Ghost" Image (Touch-through)

I have created a service which will overlay an image on top of the whole screen.

This part is the code which will overlay an image on top of the whole screen:

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

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    img = new ImageView(this);
    img.setImageResource(R.drawable.image); // Image is .png format

    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.CENTER | Gravity.CENTER;
        params.x = 0;
        params.y = 0;

        windowManager.addView(img, params);
}

However, any space which the image covers in untouchable. I want the image to be just overlaid, without affecting any other components on the screen, similar to what this does:

CPU usage overlay example

How can I make the area beneath the image touchable (touch-through)?

Edit
It seems that the transparent space of the image fills a square, and covers the screen (FYI). So my ultimate goal is, to make the image touch-through.

I have tried the popupWindow class, recommended by a few SO users, but its purpose does not fulfill my needs and does not work.

like image 308
jyoonPro Avatar asked Nov 10 '22 06:11

jyoonPro


1 Answers

I found that WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY solves the issue.

like image 123
jyoonPro Avatar answered Nov 15 '22 05:11

jyoonPro