How does the effect of darkening in other places after the Popupwindow pop-up
Realistic solution, summed up, a total of two kinds of
The first method is simple and effective:
Popupwindow's interface is the same size as the whole screen,
Just the part of the content is centered below, transparent by setting his background color transparent to cover the background behind.
Code and implementation
It's easier to modify the background color of the popup layout.
Android:background= "#b3b3b3"
Initialize Code
protected void Initpopuptwindow () { WindowManager WindowManager = getactivity (). Getwindowmanager (); Display display = windowmanager.getdefaultdisplay (); Popupwindow = new Popupwindow (Popupwindow_view, Display.getwidth (), Display.getheight (), true); Set the animation effect Popupwindow.setanimationstyle (r.style.animation_zoomlight); Click somewhere else to disappear Popupwindow_view.setontouchlistener (new Ontouchlistener () { @Override public Boolean OnTouch (View V, motionevent event) { //TODO auto-generated method Stub Closepopupwindow (); return false;}} );
As follows:
The second method of
Believe that the big guy personally try to know, the first method of the shortcomings is also obvious, he covered the original activity to achieve a transparent effect, the results of the original activity is covered, the user experience is very poor, if not, So the only way to change the transparency of the activity when the Popupwindow pops up is to have a clear view of the part that was not covered in the activity, so what? The user experience is better, but when we are ecstatic about our achievements, At this time suddenly found that as long as a popupwindow,activity transparency or translucent state, the application is obviously changed the transparency, this is not a normal thing, it will make people feel strange, so what do I do, we must do a good job in the aftermath of treatment, When the Popupwindow closed, we also manually modify the activity transparency, OK, this will not have any problem, well, very good! believe that everyone must be impatient to ask me to code, OK, I put the code also attached it
Code and implementation
Part of the code for the second scenario
/** * Create Popupwindow */protected void Initpopuptwindow () {WindowManager WindowManager = Getactivit Y (). Getwindowmanager (); Display display = Windowmanager.getdefaultdisplay (); Popupwindow = new Popupwindow (Popupwindow_view, Display.getwidth (), Display.getheight (), true); Set the animation effect Popupwindow.setanimationstyle (r.style.animation_zoomlight); Windowmanager.layoutparams params=getactivity (). GetWindow (). GetAttributes (); params.alpha=0.7f; Getactivity (). GetWindow (). SetAttributes (params); Click somewhere else to disappear Popupwindow_view.setontouchlistener (new Ontouchlistener () {@Override public boolean OnT Ouch (View V, motionevent event) {//TODO auto-generated Method Stub Closepopupwindow (); return false; } }); }/*** * Gets Popupwindow instance */private void Getpopupwindow () {if (null! = Popupwindow) { Closepopupwindow (); Return} else {Initpopuptwindow (); }}/** * Close window */private void Closepopupwindow () {if (Popupwindow! = null && popupwind Ow.isshowing ()) {Popupwindow.dismiss (); Popupwindow = null; Windowmanager.layoutparams params=getactivity (). GetWindow (). GetAttributes (); params.alpha=1f; Getactivity (). GetWindow (). SetAttributes (params); } }
The second method is as follows:
Also remember to make sure to remove the background color of layout of the first scheme. Thank you
How does the effect of darkening in other places after the Popupwindow pop-up