1、自定义对话框样式覆盖系统默认的样式
<pre name="code" class="html"><style name="Theme_dialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@drawable/transparent</item>
<item name="android:windowBackground">@drawable/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Toast</item>
</style>
2、自定义一个CustomDialog 继承Dialog 并在构造方法中修改其样式
<pre name="code" class="java">public class CustomDialog extends Dialog {
public CustomDialog(Context context) {
super(context,R.style.Theme_dialog);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout layout = (RelativeLayout) inflater.inflate(
R.layout.alert_dialog , null);//自定义自己所需布局
final int cFullFillWidth = 10000;
layout.setMinimumWidth(cFullFillWidth);
setContentView(layout);
Window window = getWindow();
WindowManager.LayoutParams params = window.getAttributes();
// set width,height by density and gravity
float density = getDensity(getContext());
params.width = (int) (width * density);
params.height = (int) (height * density);
params.gravity = Gravity.CENTER;
window.setAttributes(params);
}
3、使用
CustomDialog dialog =new CustomDialog(this);
<span style="white-space:pre"> </span>dialog.show();