in my application my created custom dialog dont have full height and i can not change and customize that.for example see this screen shot:
This can be considered as a simple hack to set your layout width for example 1000dp and height wrap content like :
<LinearLayout
android:layout_width="1000dp"
android:gravity="center"
android:padding="10dp"
android:background="@color/colorAccent"
android:orientation="vertical"
android:layout_height="wrap_content">
In case anyone is wondering how to do it for a dialog shown using DialogFragment
, you can override onCreateDialog
to return a Dialog with custom style that has windowMinWidthMajor
and minor set to 90%
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new Dialog(getActivity(), R.style.WideDialog);
}
Style:
<style name="WideDialog" parent="Base.Theme.AppCompat.Dialog">
<item name="android:windowMinWidthMajor">90%</item>
<item name="android:windowMinWidthMinor">90%</item>
</style>
You don't need to add any style for that just try below one
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.your_layout_here);
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.show();
Note: using empty style
is memory time consuming inside the processor. Instead directly use dailog.getWindow().setLayout(width,height)
.
MyDialogFragment myDialogFragment =
new MyDialogFragment(activity,arraylist.get(position).getImage());
myDialogFragment.show();
Window window = myDialogFragment.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
Just try to wrap your dialog layout in a RelativeLayout
For full width dialog you can create custom style for dialog. Code is given below for full width dialog:
<style name="Custom_Dialog" parent="ThemeOverlay.AppCompat.Light" >
<item name="windowMinWidthMajor">100%</item>
<item name="windowMinWidthMinor">65%</item>
</style>
To assign this style to the dialog's constructor, add this to onCreate()
method right after setContentView()
:
getWindow()
.setLayout(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);