So here is my onCreateView method:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
View view = inflater.inflate(R.layout.my_view, container, false);
...
return view;
}
And the layout itself is a LinearLayout with
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
For some reason, after adding the line getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
the dialog shrunk to wrap the contents; in fact, one of the TextViews is forced to wrap its one line into two lines.
I want the Dialog to fill the width of the screen, save some margin that I specify.
tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog. Dismiss the fragment and its dialog.
Showing the DialogFragment Instead, use the show() method to display your dialog. You can pass a reference to a FragmentManager and a String to use as a FragmentTransaction tag.
Android DialogFragments. DialogFragment is a utility class which extends the Fragment class. It is a part of the v4 support library and is used to display an overlay modal window within an activity that floats on top of the rest of the content. Essentially a DialogFragment displays a Dialog but inside a Fragment.
Use this line in and it will be full width, regardless of the children:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE,
android.R.style.Theme_Holo_Light_Dialog_NoActionBar_MinWidth);
}
The key is NoActionBar_MinWidth
in the theme declaration.
I solve the problem, but I don't like the cause of the problem or the solution.
The problem was this, one of the children views was
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
changing it to
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
did the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With