Custom dialog too small

后端 未结 11 2266
轻奢々
轻奢々 2020-12-10 10:53

I have an android activity that implements a custom dialog.The application is running ok but the dialog is too small,i want to display a bigger dialog.How can i achieve this

相关标签:
11条回答
  • 2020-12-10 11:34

    Setting android:minWidth and android:minHeight in the custom layout does the trick for me.

    0 讨论(0)
  • 2020-12-10 11:34

    You can add tag below

        <Space
                android:layout_width="600dp"
                android:layout_height="1dp"/>
    

    inside your parent layout , so dilog layout fill the width of screen as much as poossible.

    NOTICE android:layout_width="600dp" value should be more than screen witdth , and I think 600dp is enough for MobileScreens.

    0 讨论(0)
  • 2020-12-10 11:35
    <style name="full_screen_dialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</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:minWidth" type="dimen">600dp</item>
    </style>
    

    Use this in style.xml file and use this style in dialog class

    0 讨论(0)
  • 2020-12-10 11:37

    Change your dialog dimension on runtime:

    yourDialog.show();
    yourDialog.getWindow().setLayout((6 * width)/7, LayoutParams.WRAP_CONTENT);
    

    You can do that for both dimension, in my example i only changed the width. Hope it helps!

    EDIT

    I forgot to mention where i took width:

    DisplayMetrics metrics = getResources().getDisplayMetrics();
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;
    

    EDIT 2

    Try this code:

    Dialog yourDialog = dialogFragment.getDialog();
    yourDialog.getWindow().setLayout((6 * width)/7, (4 * height)/5);
    
    0 讨论(0)
  • 2020-12-10 11:37

    put below line in onCreate

    setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog_NoActionBar_MinWidth);
    

    original answer

    0 讨论(0)
  • 2020-12-10 11:37

    The right solution is to override the onCreateDialog method rather than onCreateView, and create your dialog with a AlertDialog.Builder, as explained in the doc: http://developer.android.com/reference/android/app/DialogFragment.html#AlertDialog

    0 讨论(0)
提交回复
热议问题