Skip to content

Instantly share code, notes, and snippets.

@vpodlesnyak
Created April 1, 2014 08:41
Show Gist options
  • Save vpodlesnyak/9910308 to your computer and use it in GitHub Desktop.
Save vpodlesnyak/9910308 to your computer and use it in GitHub Desktop.
View overlay displayed on top of all activities
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