默认情况下在DialogFragment中获取保证金?

时间:2016-08-11 19:37:11

标签: android android-dialogfragment

我正在创建一个使用对话框fragement的应用程序,看起来像这样

enter image description here

正如你所看到的,我在对话框片段中得到一个上边距,没有设置你可以从我的xml文件中看到

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/tv_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/str_add_drop"
    android:textSize="@dimen/tv_title_font_size"/>
<ImageButton
    android:background="@null"
    android:id="@+id/btn_close"
    android:layout_width="12dp"
    android:layout_height="12dp"
    android:src="@drawable/ic_close"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@id/tv_title"
    android:layout_alignBottom="@id/tv_title"
    android:layout_marginRight="5dp"
    />
<EditText
    android:id="@+id/et_drop"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/tv_title"
    android:hint="@string/hint_et_drop"
    android:padding="16dp"
    android:inputType="textVisiblePassword"/>

<DatePicker
    android:id="@+id/bpv_date"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_below="@id/et_drop"></DatePicker>
<Button
    android:id="@+id/btn_add_it"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/bpv_date"
    android:text="@string/str_add_it"
    android:textAllCaps="false"/>

</RelativeLayout>

请告诉我为什么我默认获得此保证金,我该如何纠正。

3 个答案:

答案 0 :(得分:1)

请尝试:

getWindow().requestFeature(Window.FEATURE_NO_TITLE);

但在自定义对话框的onCreate()方法中的setContentView方法之前。

答案 1 :(得分:0)

您无需在对话框xml文件中进行任何更改,只需设置对话框片段的样式即可。 下面的代码将涵盖整个活动,没有边距:

RES /值/ styles.xml

<resources>
    ...
    <!-- your dialog style -->
    <style name="DialogFragment" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowBackground">@color/white</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:layout_gravity">center</item>
        <item name="android:windowCloseOnTouchOutside">true</item>
    </style>
</resources>

YourDialogFragment.java

public class YourDialogFragment extends DialogFragment implements View.OnClickListener
{
    private Dialog mDialog;

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState)
    {
        mDialog = new Dialog(getActivity(), R.style.DialogFragment);

        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
        layoutParams.copyFrom(mDialog.getWindow().getAttributes());
        layoutParams.windowAnimations = R.style.SlideUpDownDialog;

        final View view = View.inflate(getActivity(), R.layout.dialog_fragment_layout, null);
        mDialog.getWindow().setAttributes(layoutParams);
        mDialog.setContentView(view);

        return mDialog;
    }


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

        mDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        return v;
    }

    ...
}

答案 2 :(得分:0)

styles.xml

<style name="FullScreenDialog">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">
        @android:color/transparent
    </item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

ExampleDialogFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(DialogFragment.STYLE_NO_TITLE, R.style.FullScreenDialog);
}

仅此而已,您可以在全屏模式下使用自定义对话框片段。