Android pop-up window Implementation method _android

Source: Internet
Author: User
Tags set background

An example of this article describes the Android pop-up window implementation method. Share to everyone for your reference, specific as follows:

Directly on the code:

/**
* Window--Beginner's Guide
* @param cxt 
* @param ID Resource number
* @create_time 2011-7-27 PM 05:12:49
* * Public static void Displaywindow (context cxt, int id) {
    final TextView Imgtv = new TextView (Cxt.getapplicationcontext ()); 
   imgtv.setbackgrounddrawable (Cxt.getresources (). getdrawable (ID));/Set Background
    final WindowManager wm = ( WindowManager) Cxt.getapplicationcontext (). Getsystemservice ("window");
    Windowmanager.layoutparams wmparams = new Windowmanager.layoutparams ();
    Wmparams.type = 2002;
    Wmparams.format = 1;
    Wmparams.flags = n;
    Wmparams.width = layoutparams.fill_parent;
    Wmparams.height = layoutparams.fill_parent;
    Wm.addview (IMGTV, wmparams);
    Imgtv.setonclicklistener (New Button.onclicklistener () {
      @Override public
      void OnClick (View v) {
        Wm.removeview (IMGTV);//Click, Fade the Window
      }}
    );


Don't forget to add permissions to the Androidmanifest.xml:

Copy Code code as follows:
<uses-permission android:name= "Android.permission.SYSTEM_ALERT_WINDOW"/>

Android.permission.SYSTEM_ALERT_WINDOW

Allows a program to open windows using Type_system_alert, displayed at the top of all other programs (allows an application to open windows using the TYPE Type_system_alert, shown On top of all other applications. )

The value of this First_system_window is 2000. The difference between 2003 and 2002 is that the 2003 type view is higher than the 2002 type, and can be displayed on the System dropdown status bar!

I hope this article will help you with the Android program.

Related Article

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.