Android Programming Implementation Popupwindow The background of the screen after the popup becomes translucent effect _android

Source: Internet
Author: User

This article describes the Android programming implementation of the Popupwindow screen background to become translucent effect of the method. Share to everyone for your reference, specific as follows:

When Android Popupwindow pops up, the screen background becomes translucent and the effect is common. There are many ways to achieve this. The easiest thing I can use is to set the transparency of the getwindows. No more code.

/**
* Settings Add screen background transparency
* @param bgalpha *
/public void Backgroundalpha (float bgalpha)
{
    Windowmanager.layoutparams LP = GetWindow (). GetAttributes ();
    Lp.alpha = Bgalpha; 0.0-1.0
        GetWindow (). SetAttributes (LP);
}

The reason for this is that we have to change the transparency back when the Popwindow is closed.

Popwin = new Popupwindow (Popaddnotetype, Mscreenwidth *8/10, ViewGroup.LayoutParams.WRAP_CONTENT);
Add the following code inside the Popupwindow, so that when the keyboard pops up, it won't block pop windows.
Popwin.setinputmethodmode (popupwindow.input_method_needed);
Popwin.setsoftinputmode (WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
When clicking on the blank, Hide pop window
popwin.setfocusable (true);
Popwin.setbackgrounddrawable (New bitmapdrawable ());
Backgroundalpha (1f);
Add Pop window Close event
popwin.setondismisslistener (New Popondismisslistener ());

There may be someone to ask, when I click on the screen blank, Pop window is gone, but the background is translucent, this does not ah. This is where we use an event.

/**
* The Popwin Shutdown event that pops up when new notes are added is mainly to change the background transparency
* @author CG
*
/
class Popondismisslistener Implements popupwindow.ondismisslistener{
    @Override public
    void Ondismiss () {
      //TODO auto-generated Method stub
      //log.v ("list_notetypeactivity:", "I am closing event");
      Backgroundalpha (1f);
    }
}

Above

Copy Code code as follows:
Popwin.setondismisslistener (New Popondismisslistener ());

Code is to call this event

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.