Use the addview method of windowmanager to create a view. In this way, the generated view has different effects depending on the windowmanager. layoutparams attribute.
For example, you can create a system top-level window to implement the floating window effect!
Windowmanager WM = getwindow (). getwindowmanager ();
Textview BB = new textview ();
Windowmanager. layoutparams wmparams = new windowmanager. layoutparams ();
Wmparams. type = windowmanager. layoutparams. type_application_attached_dialog;
Wmparams. format = pixelformat. translucent;
Wmparams. width = windowmanager. layoutparams. match_parent;
Wmparams. Height = windowmanager. layoutparams. wrap_content;
Try {
WM. addview (BB, wmparams );//
} Catch (exception e ){
// Todo
}
Note:
Type_application_attached_dialog window type: Like type_application_panel, but layout of the window happens as that of a top-level window, not as a child of its container.
You can add a floating form as shown in the preceding figure, but this problem exists. Only BB can accept the event, but some space afterwards cannot be used if a click event is triggered. The cause may be caused by windowmanager's
The view added by the addview method obtains the focus by default and cannot be transferred.
By checking the information, we can find that in the layoutparams attribute of windowmanager, there is a flag attribute that can be used to set the relevant get focus status.
Flag_not_touch_modal window flag: even when this window is focusable (its {@ link # flag_not_focusable is not set), allow any pointer events outside of the window to be sent to the windows behind it.
Reset the properties of windowmanager. layoutparams. The details are as follows:
Windowmanager. layoutparams Params = new windowmanager. layoutparams (
Windowmanager. layoutparams. match_parent, windowmanager. layoutparams. wrap_content,
Windowmanager. layoutparams. type_application_attached_dialog,
Windowmanager. layoutparams. flag_not_touch_modal,
Pixelformat. translucent );
Params. Gravity = gravity. Top;
Then, use the addview method of windowmanager to add BB to the screen again.