android dialog box pop-up location and transparency settings specific implementation method _android

Source: Internet
Author: User

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 Alertdialog class's GetWindow method.

Copy Code code as follows:

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 that appears 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 color is made up 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, it is opaque.
You can also set the transparency of a dialog box by setting the Alpha property of Windows. Alpha, however, ranges from 0 to 1.0. If the property value is 0, it is completely transparent, and if the value is 1.0, it is opaque (that is, a dialog box that appears normally). The following code sets the value of alpha to 0.3 to show the transparent dialog box and the Non-transparent dialog box more clearly. In this example, a background image is added that will display two dialog boxes (one is translucent and the other is opaque).

Copy Code code as follows:

Display a 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 transparency to 0.3
Lp.alpha = 0.6f;
Window.setattributes (LP);
Alertdialog.show ();

When we use certain applications, we find that when a dialog box or some modal window is displayed, the following content becomes blurred or unclear. In fact, these effects are also easy to implement in OPhone. To achieve this, we only need to set two flags for the Wndow object, as follows:

Copy Code code as follows:

Window.setflags (WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

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.