没有标题的碎片对话框问题

7
我正在尝试创建一个片段对话框,并需要完整的空间来显示信息。因此,我想禁用标题栏。但在我禁用它之后,宽度不再最大化了。
public class ArticleSearchFragment extends DialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setStyle(STYLE_NO_TITLE, getTheme());
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  View view = inflater.inflate(R.layout.article_search, container, false);
  ...
}

同时,以下是 XML:

<?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"
android:orientation="vertical">

<AutoCompleteTextView
    android:id="@+id/searchField"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="Ean / Name / Produkt Nummer"
    android:completionThreshold="1" />
<Button
   android:id="@+id/cancel"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:text="@string/cancel" />

</LinearLayout>
1个回答

13

将此代码放入您的对话框片段onCreateView()中。

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_view_image, null);
   getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
   return view;
}

它将从Dialog Fragment 中移除标题栏。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接