Android floating forms

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.