Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - adding Views onscreen, but outside the content view

Tags:

android

I'm creating a component that needs to appear above and separate from the existing UI, like sliding in from the bottom of the screen and staying anchored there, regardless of the current contentview. I'd like it to be modular and portable, so pre-supposing a FrameLayout isn't realistic.

In looking at the source for the Dialog and PopupWindow classes, it looks like they accomplish this using the Window and WindowManager classes, but I'm not able to find much in the way of documentation on these classes.

Is there a simple way to accomplish what I'm describing?

TYIA

like image 652
momo Avatar asked Nov 04 '22 03:11

momo


1 Answers

For the benefit of future searchers: the answer is to use the WindowManager class. It's pretty straightforward, despite the lack of documentation (that I could find, anyway):

WindowManager.LayoutParams wlp = new WindowManager.LayoutParams();
// assign position, dimensions, and layout behavior as properties of wlp
WindowManager wm = (WindowManager) getSystemService("window");
wm.addView(someView, wlp);
like image 63
momo Avatar answered Nov 09 '22 05:11

momo