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;略

 

转载于:https://www.cnblogs.com/jenson138/p/4354195.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值