I have created one transparent activity A. In this, I'm using surface view to play the videos. I'm able to touch the apps and activities behind this activity A. But when I click another app, the activity A goes to background and closed in an improper way. I want to make activity A always stay on top of the screen if u click another apps. I tried with many flags but no one is working correct. If want to know how to make activity window always stay on top ?
Please share your suggestions and ideas. Any help would be highly appreciated.
Tap on Display. Tap on Always-on Panel. Tap the toggle at the top to enable the feature. Tap on “Always-on” at the bottom.
android:windowIsTranslucent indicates weather the window in which the activity is present in translucent state or not.
You can use WindowManager.addView()
to add your customized View to the Window, and your can set WindowManager.LayoutParams
attributes for your View.
Here is a sample:
private WindowManager wm=null;
private WindowManager.LayoutParams wmParams=null;
private MyCustomView myView=null;
private void createView(){
myView = new MyCustomView(getApplicationContext());
wm = (WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
wmParams = new WindowManager.LayoutParams();
/**
* Window type: phone. These are non-application windows providing
* user interaction with the phone (in particular incoming calls).
* These windows are normally placed above all applications, but behind
* the status bar.
*/
wmParams.type=LayoutParams.TYPE_PHONE;
wmParams.flags=LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_NOT_FOCUSABLE;
wmParams.gravity=Gravity.LEFT|Gravity.TOP;
wmParams.x=0;
wmParams.y=0;
wmParams.width=40;
wmParams.height=40;
wm.addView(myView, wmParams);
}
Don't forget add permission in AndroidManifest.xml:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
Then, you can do anything you want in MyCustomView
out of all applications.
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