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.