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