Android dialog box [Dialog] removes the white border code

Source: Internet
Author: User

Create a styles. xml file in the values directory and write the following code:

 

<Resources>
<Style name = "dialog" parent = "@ Android: style/theme. Dialog">
<Item name = "Android: windowframe"> @ null </item>
<Item name = "Android: incluwisfloating"> true </item>
<Item name = "Android: javaswistranslucent"> false </item>
<Item name = "Android: windownotitle"> true </item>
<Item name = "Android: background"> @ Android: color/Black </item>
<Item name = "Android: windowbackground"> @ null </item>
<Item name = "Android: backgrounddimenabled"> false </item>
</Style>
</Resources>

 

 

When calling, use the alerdialog interface class. The dialog interface writes the following code:

 

Dialog dialog = new dialog (setactivity. This, R. style. Dialog );
Dialog. setcontentview (R. layout. test );
Dialog. Show ();

 

Next, let's take a look at the dialog source code file. The constructor is as follows:

 

Public Dialog (context, int theme ){
Mcontext = new contextthemewrapper (
Context, theme = 0? Com. Android. Internal. R. style. theme_dialog: theme );
Mwindowmanager = (windowmanager) Context. getsystemservice ("window ");
Window W = policymanager. makenewwindow (mcontext );
Mwindow = W;
W. setcallback (this );
W. setwindowmanager (mwindowmanager, null, null );
W. setgravity (gravity. center );
Muithread = thread. currentthread ();
Mdismisscancelhandler = new dismisscancelhandler (this );
}

 

We can see that android uses the default constructor to set a style for dialog. If no style is set for it, the style file prepared in advance is loaded by default. dialog is composed of multiple 9.png images with borders, this is why the Style File above should be removed from the background. I have been using this item for a long time. I hope it will help you.

 

 

Effect Comparison

Before setting:

 

After setting:

Related Article

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.