如何去除Dialog(不是AlertDialog也不是DialogFragment)的白角?

问题描述 投票:0回答:2

我像这样创建了

line_dialog_border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <solid android:color="@color/white"/>
    <corners android:radius="20dp"/>
    <stroke
            android:width="5dp"
            android:color="@android:color/black"/>
</shape>

enter image description here

这是

kt

中的对话框
private fun showInternetCheckDialog(context: Context) {
    internetCheckDialog = Dialog(context)
    internetCheckDialog.setContentView(R.layout.dialog_internet_check)
    internetCheckDialog.window!!.requestFeature(Window.FEATURE_NO_TITLE)
    internetCheckDialog.window!!
          .setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
    internetCheckDialog.window!!
          .decorView.setBackgroundResource(R.drawable.line_dialogue_border)
    internetCheckDialog.setCanceledOnTouchOutside(false)

    val btnOk = internetCheckDialog.btn_ok

    btnOk.setOnClickListener {
        internetCheckDialog.dismiss()
    }

    try {
        if (!internetCheckDialog.isShowing) {
            internetCheckDialog.show()
        }
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

这样的问题还有很多。但我只看到

AlertDialog
DialogFragment

我已经尝试过

dialog.window!!
    .setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog.window!!
    .decorView.setBackgroundResource(R.drawable.line_dialogue_border)
dialog.window!!.setBackgroundDrawableResource(android.R.color.transparent);

这是布局 xml。我只是用上面创建的

xml
给出背景属性。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/line_dialog_border"
        android:padding="20dp"
        android:orientation="vertical">

    <TextView
            android:id="@+id/tv_message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:textColor="@android:color/black"
            android:lineSpacingExtra="10dp"
            android:text="No\nInternet\nConnection"
            android:textAlignment="center"
            android:textSize="24sp"
    />
</RelativeLayout>

但没有任何结果。 我该怎么办?

android android-styles android-dialog
2个回答
1
投票

也许您应该正确设置对话框窗口或创建自定义 style.xml

Window window=this.getWindow();
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

style.xml:

<style name="DialogActivityStyle">
<item name="android:background">@android:color/white</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>

AndroidMainfest:

<activity android:name=".YourActivity"
          android:theme="@style/DialogActivityStyle"/>

0
投票
Add this code piece before calling show(),

if (alertDialog.getWindow() != null)
{
    alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
© www.soinside.com 2019 - 2024. All rights reserved.