android Dialog实例

Dialog类

 1 public class DialogUtil {
 2 
 3     public static Dialog EditDialog(Activity context,View view){
 4         final Dialog dialog = new Dialog(context, R.style.dialogStyle);
 5         dialog.setContentView(view);
 6         Window window = dialog.getWindow();
 7         WindowManager.LayoutParams lp = window.getAttributes();
 8         int screenWidth = getScreenWidth(context);
 9         lp.width =screenWidth;
10         window.setGravity(Gravity.CENTER);
11         return dialog;
12         
13     }
14     
15     public static int getScreenWidth(Activity context) {
16         DisplayMetrics dm = new DisplayMetrics();
17         context.getWindowManager().getDefaultDisplay().getMetrics(dm);
18         return dm.widthPixels;
19     }
20 
21     public static int getScreenHeight(Activity context) {
22         DisplayMetrics dm = new DisplayMetrics();
23         context.getWindowManager().getDefaultDisplay().getMetrics(dm);
24         return dm.heightPixels;
25     }
26     
27 }

style

1     
2     <style name="dialogStyle">
3         <item name="android:windowBackground">@android:color/transparent</item>
4         <item name="android:windowNoTitle">true</item>
5         <item name="android:windowIsTranslucent">true</item>
6         <item name="android:windowContentOverlay">@null</item>
7         <item name="android:windowFullscreen">false</item>
8         <item name="android:windowIsFloating">true</item>
9     </style>

调用:

    private Dialog mEditNameDialog;
    private void showEditDialog(){
        if (mEditNameDialog == null){
            View v = LayoutInflater.from(this).inflate(R.layout.dialog_meeting_detailed_edit_name, null); 
            mEditNameDialog = DialogUtil.MeetingDetailedEditName(this, v);
            mEditNameDialog.show();
        }else{
            if (mEditNameDialog.isShowing())
            mEditNameDialog.dismiss();
            else
                mEditNameDialog.show();
        }
    }

 .xml;略

 

技术分享

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。