Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DialogFragment with no title shrinks dialog width

The goal is to create a dialog that shows a list of files.

The problem is that once I remove the title (by any means including window feature, setting style, using styles.xml...) the dialog window converts to wrap_content constraint.

No property I set in layout influences this.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

    <TextView
        android:id="@+id/dialog_files_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:padding="8dp"
        android:text="@string/dialog_files_title"
        android:textColor="@color/colorTextActive"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Title" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/dialog_files_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp" />

</LinearLayout>

my java code

public Dialog onCreateDialog(Bundle savedInstanceState) {

        Dialog dialog = super.onCreateDialog(savedInstanceState);

        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);

        return dialog;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.dialog_files, null);

        paths = new ArrayList<>();
        recursiveScan(Environment.getExternalStorageDirectory());
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.dialog_files_recycler_view);
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), 3);
        AdapterFiles adapter = new AdapterFiles(getActivity(), paths);

        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);

        return view;

    }

The result is this

dialog

like image 570
ZooS Avatar asked Nov 11 '16 14:11

ZooS


1 Answers

The issue seems to be when using LinearLayout as a root layout. I switched to RelativeLayout everything fit into place. Maybe this is a bug when using LinearLayout as a root layout in dialogs and removing title?

like image 172
ZooS Avatar answered Oct 02 '22 14:10

ZooS