Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DialogFragment width shrink after specifying FEATURE_NO_TITLE

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.

like image 388
user3093402 Avatar asked Dec 12 '13 17:12

user3093402


People also ask

How do I destroy DialogFragment?

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.

How do I know if DialogFragment is showing?

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.

What is DialogFragment?

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.


2 Answers

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.

like image 69
Paul Burke Avatar answered Oct 29 '22 04:10

Paul Burke


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.

like image 31
user3093402 Avatar answered Oct 29 '22 06:10

user3093402