在Android 4.4.2中,DialogFragment在顶部有一条蓝色的线。

9

enter image description here

我的对话框片段上方出现了一条蓝色线,我无法去掉它(我甚至不知道为什么它首先会出现。有人知道如何去掉它吗?

我已在多台设备上进行了测试,它在较新的Android版本上运行良好。

我的代码:

    private void setupDialog() {
    final Dialog dialog = getDialog();
    final Window window = dialog.getWindow();

    window.setBackgroundDrawable(new ColorDrawable(0));
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }

布局:

      <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tiktok="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/settings_bg">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true">

        <ImageView
            android:id="@+id/close_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_margin="15dp"
            android:src="@drawable/pressable_close_btn"/>

        <com.cyscorpions.timekeeper.customviews.TKTextView
            android:id="@+id/settings_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/dp_40"
            android:text="@string/settings_allcaps"
            android:textColor="@color/timekeeper_blue"
            android:textSize="@dimen/sp_60"
            tiktok:useBoldFont="true"/>

        <com.cyscorpions.timekeeper.customviews.TKTextView
            android:id="@+id/account_name_instruction"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/settings_title"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/dp_20"
            android:text="@string/subdomain_instruction"
            android:textColor="@color/gray"
            android:textSize="@dimen/sp_30"/>

        <RelativeLayout
            android:id="@+id/info_field"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/dp_70"
            android:layout_alignLeft="@+id/submit_btn"
            android:layout_below="@id/account_name_instruction"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="@dimen/dp_20">

            <com.cyscorpions.timekeeper.customviews.TKAppCompatEditText
                android:id="@+id/subdomain_textfield"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:background="@drawable/text_field_bg"
                android:hint="@string/textfield_account_hint"
                android:inputType="text"
                android:textColor="@color/gray"
                android:textColorHint="@color/gray"
                android:textSize="@dimen/sp_20"
                tiktok:setTextFieldFont="@string/montserrat_reg"/>

            <com.cyscorpions.timekeeper.customviews.TKTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@id/subdomain_textfield"
                android:text="@string/domain_suffix"
                android:textColor="@color/gray"
                android:textSize="@dimen/sp_25"/>
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/error_tooltip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/settings_title">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/error_tooltip"
                android:shadowColor="@color/black"/>

            <com.cyscorpions.timekeeper.customviews.TKTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="@dimen/dp_20"
                android:text="@string/field_required"
                android:textColor="@color/white"
                android:textSize="@dimen/sp_30"/>
        </RelativeLayout>

        <com.cyscorpions.timekeeper.customviews.TKButton
            android:id="@id/submit_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/info_field"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="@dimen/dp_10"
            android:background="@drawable/pressable_submit_btn"
            android:text="@string/submit_allcaps"
            android:textColor="@color/white"
            android:textSize="@dimen/sp_30"
            tiktok:hasDarkerPressedState="true"
            tiktok:useDefaultDrawable="true"/>

    </RelativeLayout>

</RelativeLayout>
3个回答

27

我猜当仍有标题栏时它会出现。我刚刚隐藏了标题栏,它就正常工作了。

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

9
只有当我们将这些代码放在“setContentView”之前时,它才会起作用,否则就会抛出异常 :) - Ravindra Kushwaha
1
此外,它还修复了一些布局重力问题 ;) - Tobliug

0
    var filterDialog=FilterDialog(mContext,"","","")
    filterDialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
    filterDialog.window!!.setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
    filterDialog.window!!.requestFeature(Window.FEATURE_NO_TITLE)//add this line.
    filterDialog.show()

添加

filterDialog.window!!.requestFeature(Window.FEATURE_NO_TITLE)

-1

使用以下更改:

在您的DialogFragment上:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setStyle(android.support.v4.app.DialogFragment.STYLE_NO_FRAME, R.style.my_dialog_style);
}

在你的样式R.style.my_dialog_style中添加以下内容:
<item name="android:windowContentOverlay">@null</item>

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