Android custom dialog
1. Create a dialog layout, as shown in figure
2. declare the following style in style:
3. Call the following method where you want to create
/*** Display the pop-up window when the login information expires * @ param ctx context object */private static void initErrDialog (final Context ctx) {final Dialog dialog = new Dialog (ctx, R. style. tokenDialog); Window dialogWindow = dialog. getWindow (); dialogWindow. setGravity (Gravity. CENTER); // displayed in the CENTER dialog. setCanceledOnTouchOutside (false); // you can click any external area of Dialog to disable Dialog View = LayoutInflater. from (ctx ). inflate (R. layout. pop_token_outofdate_tips, null); Butt On exitbtn = (Button) view. findViewById (R. id. pop_exit); Button reloginBtn = (Button) view. findViewById (R. id. pop_relogin); TextView errTxt = (TextView) view. findViewById (R. id. token_err); Long timemills = System. currentTimeMillis (); Date dat = new Date (timemills); GregorianCalendar gc = new GregorianCalendar (); // GregorianCalendar is a specific subclass of Calendar. gc. setTime (dat); SimpleDateFormat format = new SimpleDate Format (HH: mm); // 24 hour String time = format. format (gc. getTime (); errTxt. setText (Html. fromHtml (your account is logged on to another mobile phone at + time +. If not my operation, the password may have been leaked, + It is recommended to go to The http://www.daokoudai.com to change the password .)); Exitbtn. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {dialog. dismiss (); android. OS. process. killProcess (android. OS. process. myPid (); // exit the entire application}); reloginBtn. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {dialog. dismiss (); TabMainActivity. getInst (). finish (); // finish () The current activity, otherwise there will be a dialog // do not know dialog. dismiss () Why TabMainActivity is abnormal. getInst (). startActivity (new Intent (TabMainActivity. getInst (), LoginActivity. class) ;}}); dialog. setContentView (view); dialog. show ();}