Android uses code to set dialog style

Source: Internet
Author: User

You cannot use the style file to format dialog because of project requirements. This can worry about the baby, in the internet search for a bit, basically is the use of style file settings.

1. Setting the default background of dialog

Normally the dialog has a window-level background, which is the black shadow background around the dialog we usually encounter. Using code:

This.getwindow (). Setbackgrounddrawableresource (r.drawable.bg_text_bounced); This.getwindow (). Setbackgrounddrawable (drawable);

is generally set to rounded corners, so I cut a fillet background picture is good, this refers to the dialog, do not get the context of GetWindow, this window set or no effect, so must be in the dialog window set background

Dialog.getwindow (). Setbackgrounddrawableresource (r.drawable.bg_text_bounced);d Ialog.getwindow (). Setbackgrounddrawable (drawable);

2. Other property settings

Setting does not display the dialog box title bar

requestwindowfeature (Window. Feature_no_title );

Go to the Shadows

GetWindow (). Clearflags (Windowmanager.layoutparams. Flag_dim_behind );

Set background

GetWindow (). Setbackgrounddrawableresource (r.drawable. vip_p );


Content Transparency

Windowmanager.layoutparams wmparams =getwindow (). GetAttributes ();

Wmparams.format = pixelformat.transparent; Content is fully transparent

wmparams. format =pixelformat. translucent //content translucent   

Wmparams. Alpha =1.0f; //Adjust transparency, 1.0 max

Dialog setting various properties

GetWindow (). SetAttributes (Wmparams);


3, temporarily first think up above two, then think up and then continue to add

This article is from the "Vivian Son" blog, please be sure to keep this source http://9550674.blog.51cto.com/9540674/1891849

Android uses code to set dialog style

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.