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

时间:2012-12-03 14:42:56

标签: java android

我正在尝试创建一个片段对话框,需要完整的空间来显示信息。所以我想禁用标题栏。但是在我禁用之后,宽度不再最大化了。

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 个答案:

答案 0 :(得分:13)

将此代码放入onCreateView() dialog fragment

@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

它将从{{1}}

中删除标题栏