Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create always-top fullscreen overlay activity in Android

Tags:

I'd like to be able to create an Activity that is always at the front of display of Android. It should receive no input, just pass it down to whatever application is next below it. Something like a HUD.

I was able to research that I need to set underlying window type to TYPE_SYSTEM_ALERT but it looks like Android is ignoring my code - no exception thrown even if I delete android.permission.SYSTEM_ALERT_WINDOW permission from manifest. (it is required to use this window type). When I tried to use ALERT type on dialog, it worked OK, but I cannot make dialog into full screen transparent entity. Here is my code, maybe there is something simple missing.

public void onCreate(Bundle savedInstanceState) {             super.onCreate(savedInstanceState);               requestWindowFeature(Window.FEATURE_NO_TITLE);      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);      getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);                   getWindow().setBackgroundDrawableResource(android.R.color.transparent);      getWindow().setFormat(PixelFormat.TRANSLUCENT);      setContentView(R.layout.main); } 

Translucent setting has to be enabled externally in xml manifest, otherwise it also didn't work.

 <item name="android:windowIsTranslucent">true</item> 
like image 659
tmouse Avatar asked Apr 10 '12 19:04

tmouse


People also ask

How do I make my Android activity full screen?

Using Android Studio (current version is 2.2. 2 at moment) is very easy to add a fullscreen activity. See the steps: Right click on your java main package > Select “New” > Select “Activity” > Then, click on “Fullscreen Activity”.


1 Answers

final WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, PixelFormat.TRANSLUCENT);  WindowManager wm = (WindowManager) getApplicationContext()     .getSystemService(Context.WINDOW_SERVICE);  ViewGroup mTopView = (ViewGroup) App.inflater.inflate(R.layout.main, null); getWindow().setAttributes(params); wm.addView(mTopView, params); 
like image 169
tmouse Avatar answered Sep 18 '22 18:09

tmouse