Customizing the Dialog dialog box

Source: Internet
Author: User

Custom Dialogpackage com.zhiduan.crowdclient.view;import com.zhiduan.crowdclient.myapplication;import  com.zhiduan.crowdclient.R;import android.app.Activity;import android.app.Dialog;import  android.content.context;import android.view.display;import android.view.gravity;import  Android.view.layoutinflater;import android.view.view;import android.view.view.onclicklistener;import  android.view.window;import android.view.windowmanager;import android.widget.button;import  android.widget.ImageView;/**  *  Single Sign-on prompt window (this account is logged in on another device)  *  *  @author  yxx * *  @date  2016-5-3  pm 10:00:31 *  */public class  Singlelogindialog{public static boolean isshow = false;static dialog dialog ;//  Popup result callback function public static abstract class resultcallback {public abstract  void callback (boolean  result);} Public singlelogindialog (context context) {}/** *  @param  context *  @param  strmessage */public static void showmydialog (context context, final  Resultcallback callback) {if (dialog != null) {Dialog.dismiss ();} Dialog = new dialog (Context, r.style.dialog); Layoutinflater inflater = dialog.getlayoutinflater (); View layout = inflater.inflate (R.layout.dialog_single_login, null); button btnok =  (Button)  layout.findviewbyid (R.ID.BTN_SINGLE_LOGIN_OK); ImageView img  =  (ImageView)  layout.findviewbyid (r.id.imageview1); Btnok.setonclicklistener (new  Onclicklistener ()  {@Overridepublic  void onclick (view arg0)  {callback.callback (true); Dialog.dismiss ();}}); Img.setonclicklistener (New onclicklistener ()  {@Overridepublic  void onclick (View arg0)  {// todo autO-generated method stubdialog.dismiss ();}}); Dialog.setcontentview (layout);d ialog.setcancelable (False);d Ialog.setcanceledontouchoutside (False);d Ialog.show ( ); setdialogwindowattr (dialog, context); isshow = true;} /** *  Close Window  */public static void closedialog () {singlelogindialog.isshow =  false;if (dialog != null) {Dialog.dismiss ();}} Call Public static void setdialogwindowattr (DIALOG&NBSP;DLG,CONTEXT&NBSP;CTX) after Dialog.show () { windowmanager wm =  (Activity)  ctx). Getwindowmanager ();D isplay display =  Wm.getdefaultdisplay (); //  to get the screen width, high window window = dlg.getwindow (); Windowmanager.layoutparams lp = window.getattributes ();lp.gravity = gravity.center; lp.width =  (int)   (display.getwidth ()/1.5);lp.height =  (int)   (Display.getheight () /3);d Lg.getwindow (). SetAttributes (LP);}} styles.xml    <style name= "Dialog"  parent= "@android: Style/theme.dialog" >         <item name= "Android:windowframe" > @null </item>         <item name= "Android:windowisfloating" >true</item>         <item name= "Android:windowistranslucent" >false</item>         <item name= "Android:windownotitle" >true</item>         <item name= "Android:background" > @android: color/transparent</ Item>        <item name= "Android:windowBackground" >@ android:color/transparent</item>        <!--  Hide title bar   -->        <item name= "Android:backgrounddimenabled" > true</item>         <item name= "Android:backgrounddimamount" >0.6</item>         <!--  Grayscale  -->    < in the outer area of the dialog box /style>

This article is from the "climb over the mountains to see the Sea" blog, please be sure to keep this source http://670176656.blog.51cto.com/4500575/1786985

Customizing the Dialog dialog box

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.