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: