一、第一种方法
在自定义的dialog的OnCreat 方法中加上
getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);如:
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); this.getWindow().requestFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.edit_dialog); getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); this.setCanceledOnTouchOutside(false);
在dialog.show()方法执行之后,加上如下代码:
WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); WindowManager.LayoutParams lp = dialog.getWindow().getAttributes(); lp.width = (int)(display.getWidth()); //设置宽度 dialog.getWindow().setAttributes(lp);
4.0上如果还用Theme.Dialog,只能说很土,跟整体UI风格差别很大
请使用android:theme="@android:style/Theme.Holo.DialogWhenLarge"
上效果对比图:
@android:style/Theme.Holo.DialogWhenLarge:
@android:style/Theme.Dialog