Android custom dialog

Source: Internet
Author: User

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 ();}

 

 

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.