Custom Dialog in full screen?

前端 未结 11 1983
终归单人心
终归单人心 2020-12-08 13:35

Is there any way to make my Dialog view full screen, i.e dialog occupy the entire screen (like an Activity). I tried using the LayoutParams and styles like

相关标签:
11条回答
  • 2020-12-08 13:51

    Following code works in my case :

    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.setContentView(R.layout.mydialog2);
    dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
    
    0 讨论(0)
  • 2020-12-08 13:52

    Create your Custom Dialog as

    Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
    
    0 讨论(0)
  • 2020-12-08 13:53

    Give its constructor a non-dialog theme, such as android.R.style.Theme or android.R.style.Theme_Light.

    Code by @Bob.

    Dialog dialog = new Dialog(context, android.R.style.Theme_Light); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.setContentView(R.layout.MyCustomDialogLayout); 
    dialog.show();
    
    0 讨论(0)
  • 2020-12-08 13:54

    For full screen dialog you should extend DialogFragment it will provide Fragment life cycle methods and this is the recommended way in Android developer documents you can use simple Dialog or AlertDialog also.

    When you create dialog instance just use android.R.style.Theme_Black_NoTitleBar_Fullscreen theme with context like this :

    Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    

    or

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    

    This will show the dialog in full screen.

    0 讨论(0)
  • 2020-12-08 13:56

    1.custom your dialog style

     <style name = "MyDialog" >
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowFullscreen">true</item>
            <item name="android:windowIsTranslucent">true</item>
            <item name = "android:windowContentOverlay" >@null</item >
            <item name = "android:colorBackgroundCacheHint" >@null</item >
            <item name = "android:backgroundDimEnabled">true</item>
            <item name = "android:windowBackground" >@android:color/transparent</item >
        </style >

    2 :custom your dialog

    WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
                int width = wm.getDefaultDisplay().getWidth();
                int height = wm.getDefaultDisplay().getHeight();
                final Dialog dialog = new Dialog(this, R.style.MyDialog);
                View view = LayoutInflater.from(this).inflate(R.layout.layout_dialog, null);
    
                WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
                params.width = WindowManager.LayoutParams.MATCH_PARENT;
                params.height = WindowManager.LayoutParams.WRAP_CONTENT;
    
                dialog.setContentView(view);
                dialog.getWindow().setGravity(Gravity.BOTTOM);
                dialog.getWindow().setWindowAnimations(R.style.mydialog_Style);
                dialog.show();

    0 讨论(0)
  • 2020-12-08 13:57

    Try this

    dialog = new Dialog(context,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
    
    0 讨论(0)
提交回复
热议问题