Created
April 1, 2014 08:41
-
-
Save vpodlesnyak/9910308 to your computer and use it in GitHub Desktop.
View overlay displayed on top of all activities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OverlayService extends Service { | |
LinearLayout oView; | |
@Override | |
public IBinder onBind(Intent i) { | |
return null; | |
} | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
oView = new LinearLayout(this); | |
oView.setBackgroundColor(0x88ff0000); // The translucent red color | |
WindowManager.LayoutParams params = new WindowManager.LayoutParams( | |
WindowManager.LayoutParams.MATCH_PARENT, | |
WindowManager.LayoutParams.MATCH_PARENT, | |
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, | |
0 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, | |
PixelFormat.TRANSLUCENT); | |
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); | |
wm.addView(oView, params); | |
} | |
@Override | |
public void onDestroy() { | |
super.onDestroy(); | |
if(oView!=null){ | |
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); | |
wm.removeView(oView); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment