使用
public class AddPersonDialogFragment extends BaseDialogFragment {
@Override
public View onCreateView(Bundle savedInstanceState,
LayoutInflater inflater, ViewGroup container) {
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
View view = inflater.inflate(R.layout.dialogfragment_addperson, container);
return view;
}
}
BaseDialogFragment是自己定义的,其实就是继承dialogFragment
AddPersonDialogFragment fragment = new AddPersonDialogFragment();
fragment.show(getFragmentManager(), "你的信息");
就可以显示出来了
如果要隐藏标题 则:
public class AddPersonDialogFragment extends BaseDialogFragment {
@Override
public View onCreateView(Bundle savedInstanceState,
LayoutInflater inflater, ViewGroup container) {
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
View view = inflater.inflate(R.layout.dialogfragment_addperson, container);
return view;
}
}
但是这样,会有个问题,无论在布局文件中写多宽,都是wrap_content
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="700dp"
android:layout_height="600dp"
android:orientation="vertical" >
<TextView
android:id="@+id/id_label_your_name"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:gravity="left"
android:text="Your name:" />
<TextView
android:id="@+id/person_name_textview"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:gravity="right"
android:text="asl" />
<!--
<EditText
android:id="@+id/id_txt_your_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/id_label_your_name"
android:imeOptions="actionDone"
android:inputType="text" />
<Button
android:id="@+id/id_sure_edit_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/id_txt_your_name"
android:text="ok" />
-->
</LinearLayout>