1功茴、聲明一個(gè)style
<style name="Dialog.FullScreen" parent="Theme.AppCompat.Dialog">
<item name="android:padding">0dp</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
2落追、在DialogFragment中引用
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, R.style.Dialog_FullScreen);
}
3叠赐、如果想將周邊設(shè)置指定的透明值戚篙,可以在DialogFragment中的onStart設(shè)置
@Override
public void onStart() {
super.onStart();
Window window = getDialog().getWindow();
WindowManager.LayoutParams windowParams =window.getAttributes();
windowParams.dimAmount = 0.7f; //將Window周邊設(shè)置透明為0.7
getDialog().setCanceledOnTouchOutside(false); //點(diǎn)擊周邊不隱藏對(duì)話框
window.setAttributes(windowParams);
//點(diǎn)擊返回鍵不隱藏對(duì)話框
getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
return true;
}
return false;
}
});
}