In Android we often use Alertdialog to display dialog boxes. Through this dialog box is displayed in the center of the screen. In some programs, however, the Requirement dialog box can be displayed in a different location. For example, above or below the screen. To achieve this effect. You need to get the Window object for the dialog box, there are several ways to get the Window object. The easiest thing to do is to get the window object directly through the GetWindow method of the Alertdialog class.
Alertdialog dialog = new Alertdialog.builder (this). Settitle ("title")
. Setmessage ("message"). Create ();
window window = Alertdialog.getwindow ();
Window.setgravity (Gravity.top); Window.setgravity (Gravity.bottom);
Alertdialog.show ();
Transparent dialog box
The dialog box shown by default is opaque, but we can make it transparent or translucent by setting the Alpha value of the dialog box. We all know that. The colors consist of R (Red), G (green), B (blue). In addition, there will be a (transparency, Alpha) to describe the color. In the description of the color, if the value is 0 for full transparency, if the value is 255, the opacity is indicated.
You can also set the transparency of a dialog box by setting the Alpha property of Windows. But the alpha value range is from 0 to 1.0. If the value of this property is 0, it is fully transparent, and if the value is 1.0, it is opaque (that is, the dialog box is displayed normally). The following code, by setting the value of alpha to 0.3, displays transparent dialog boxes and opaque dialogs more clearly. In this example, a background image is added, and two dialog boxes are displayed (one is translucent and the other is opaque).
Show Transparent dialog box
Alertdialog Alertdialog = new Alertdialog.builder (this). Setmessage (
Transparent dialog box). Setpositivebutton ("OK", null). Create ();
window window = Alertdialog.getwindow ();
Windowmanager.layoutparams LP = Window.getattributes ();
Set the transparency to 0.3
Lp.alpha = 0.6f;
Window.setattributes (LP);
Alertdialog.show ();
When we use some apps, we find that when a dialog box or some modal window pops up, the content behind it becomes blurry or unclear. In fact, these effects can also be easily implemented in OPhone. To implement this function, we only need to set the two flags of the Wndow object, the code is as follows:
Window.setflags (WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Android dialog box popup position and transparency settings