Can I create an UI or a widget in Android that will sit on top of all applications? There are applications that have widgets like this. One example has a camera icon on top of all the applications that, when clicked, will capture the screen.
If you want to just display something, you can display it on top of everything even the lockscreen.
If you want something to be clickable, you can display it on top of anything except the lockscreen.
Here's a sample, modify to your needs:
Create a service and do the following:
//These three are our main components.
WindowManager wm;
LinearLayout ll;
WindowManager.LayoutParams ll_lp;
//Just a sample layout parameters.
ll_lp = new WindowManager.LayoutParams();
ll_lp.format = PixelFormat.TRANSLUCENT;
ll_lp.height = WindowManager.LayoutParams.FILL_PARENT;
ll_lp.width = WindowManager.LayoutParams.FILL_PARENT;
ll_lp.gravity = Gravity.CLIP_HORIZONTAL | Gravity.TOP;
//This one is necessary.
ll_lp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
//Play around with these two.
ll_lp.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
ll_lp.flags = ll_lp.flags | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
//This is our main layout.
ll = new LinearLayout(this);
ll.setBackgroundColor(android.graphics.Color.argb(0, 0, 0, 0));
ll.setHapticFeedbackEnabled(true);
//And finally we add what we created to the screen.
wm.addView(ll, ll_lp);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With