1: 首先是样式:
<style name="CustomDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowCloseOnTouchOutside">false</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="NotCloseOnTouchOutDialog" parent="@style/CustomDialog">
</style>
2: 然后自定义view
public class NoWifiDialog extends Dialog{
public NoWifiDialog(Context context) {
this(context, R.style.NotCloseOnTouchOutDialog);
}
public NoWifiDialog(final Context context, int themeResId) {
super(context, themeResId);
View v= LayoutInflater.from(context).inflate(R.layout.dialog_nowifi,null);
Button btnIgnore= (Button) v.findViewById(R.id.btn_ignore);
Button btnOpenWifi= (Button) v.findViewById(R.id.btn_openWifi);
btnIgnore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
btnOpenWifi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
}
});
setContentView(v);
}
}