Code reuse is important! dialog box in addition to the content, the display style is the same, we will create a factory class.
public class Dialogfactory {public static Dialog Creatrequestdialog (final context context, String tip) {final Dialog Dialo g = new Dialog (context, R.style.dialog);d Ialog.setcontentview (r.layout.dialog_layout); window window = Dialog.getwindow (); Windowmanager.layoutparams LP = Window.getattributes (); int width = utils.getscreenwidth (context); lp.width = (int) (0.6 * width); TextView TITLETXTV = (TextView) Dialog.findviewbyid (r.id.tvload); if (tip = = NULL | | tip.length () = = 0) {Titletxtv.settext ( "Sending request");} else {titletxtv.settext (tip);} return dialog;}}
Call Method:
Private Dialog mdialog = null; private void Showrequestdialog () {if (Mdialog! = null) {Mdialog.dismiss (); Mdialog = null;} Mdialog = Dialogfactory.creatrequestdialog (This, "Verifying account ..."); Mdialog.show (); }
Values folder in Style.xml
<style name= "Dialog" parent= "@android: Style/theme.dialog" > <item name= "Android:windowisfloating" >true</item> <!-- Set up non-floating windows --> <item name= "Android:windowframe" > @null </item> <!-- Set no Border --> <item name= "Android: Windownotitle ">true</item> <!-- Set Untitled -- > <item name= "Android:windowbackground" > @color/sc _transparent_background</item> <!-- Set fully transparent - -> <item name= "Android:backgrounddimenabled" >true </item> <!-- Settings screen dimming --> </style >
This article is from the information security-database security blog, so be sure to keep this source http://fergusj.blog.51cto.com/8835051/1689321
Android uses the Factory class Create dialog box