版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Rodulf/article/details/86534816
Done!!!!!!
1: 做一个只遮挡navigationbar的背景
2: 在style 里面设置windowbackground这个背景,记住一定是这个windowbackground 而不是background
3: getwindow的时候设置高度为整个屏幕的高度,
4:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="290dp" android:orientation="vertical"> <Button android:layout_width="match_parent" android:layout_height="20dp" android:text="click1"/> </LinearLayout>
<style name="AppThemeDialogFull" parent="ThemeOverlay.AppCompat.Dialog.Alert"> <!-- Customize your theme here. --> <item name="android:backgroundDimAmount">0.5</item> <item name="android:backgroundDimEnabled">false</item> <item name="android:windowNoTitle">true</item> <item name="android:layout_gravity">bottom</item> <item name="android:windowBackground">@mipmap/background_1</item> </style>
package bjpkten.systemuiflagtest; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.view.Gravity; import android.view.ViewGroup; import android.view.WindowManager; /** * Created by Kodulf on 2019/1/15. */ public class MyDialog extends Dialog { public MyDialog( Context context) { super(context); // getWindow().requestFeature(Window.FEATURE_NO_TITLE); // getWindow().setDimAmount(0.5f); // getWindow().setBackgroundDrawable(R.mipmap.background_1); } public MyDialog( Context context, int themeResId) { super(context, themeResId); } protected MyDialog( Context context, boolean cancelable, DialogInterface.OnCancelListener cancelListener) { super(context, cancelable, cancelListener); } @Override public void show() { // getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); // getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); // getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); // getWindow().getDecorView().setPadding(0,0,0,0); // WindowManager.LayoutParams attributes = getWindow().getAttributes(); // attributes.width= 1000; // attributes.height = 2800; // this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); super.show(); getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,320); getWindow().setGravity(Gravity.BOTTOM); // getWindow().setGravity(Gravity.TOP); // getWindow().getDecorView().setPadding(0,0,0,0); // getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN|WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS|WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); // getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // getWindow().setNavigationBarColor(Color.parseColor("#474747")); // getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); // this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); // getWindow().getDecorView().setPadding(300,300,300,300); // getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); // getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); // getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } }