Hover windows in Android

Source: Internet
Author: User

Call WindowManager, and set Windowmanager.layoutparams related properties, through the WindowManager AddView method to create a view, so that the resulting view according to the Windowmanager.layoutparams attribute, the effect is different. For example, create a system top-level window to achieve the hover window effect!
WindowManager method is very simple, the basic use of the three addview,removeview,updateviewlayout.
The properties of Windowmanager.layoutparams are much, very rich, see the SDK documentation for details. This gives the Android Windowmanager.java source code, can be specific to see.
The following is a simple example code:

[Java]
public class Myfloatview extends Activity {
/** called when the activity is first created. */
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Button Bb=new button (Getapplicationcontext ());
WindowManager wm= (WindowManager) Getapplicationcontext (). Getsystemservice ("window");
Windowmanager.layoutparams wmparams = new Windowmanager.layoutparams ();

/**
* The following are the relevant properties of Windowmanager.layoutparams
* For specific applications, please refer to the SDK documentation
*/
wmparams.type=2002; Here is the key, you can also try 2003
Wmparams.format=1;
/**
* The flags here are also critical
* Code is actually wmparams.flags |= flag_not_focusable;
The origin of the *40 is the default attribute of Wmparams (+ flag_not_focusable) (8)
*/
wmparams.flags=40;
wmparams.width=40;
wmparams.height=40;
Wm.addview (BB, wmparams); CREATE view
}
}
Don't forget to add permissions in Androidmanifest.xml:
[Java]
<span><</span>uses<span>-</span>permission android<span>:</span>name< Span>=</span><span> "Android.permission.SYSTEM_ALERT_WINDOW" </span> <span>/></ Span>
PS: Here is an example of the meaning of the value of type:
[Java]
The value of this First_system_window is 2000. The difference between 2003 and 2002 is that the 2003 type of view is top of the 2002 type and can be displayed on the system drop-down status bar!


Note: The use of Popuwindow to achieve the suspension of the video player, can achieve more open, and let the player in the forefront, interested friends can do a try.

Hahashui123

Hover windows in Android

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.