安卓可绘制背景边角无法移除

8
我将在我们的xml布局中应用可绘制的背景,但它还包含边框,如何删除它?
当我添加角落时,它会应用于角落,但它不会应用于整个布局(意味着内容不会超出边框区域)。

custom dialog box image

这是我的可绘制文件

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

<solid
    android:color="#fff">

</solid>

<stroke
    android:width="2dp"
    android:color="@color/block_button_bg">

</stroke>

<corners
    android:radius="10dp">

</corners>


</shape>

这是我的 XML 布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:background="@drawable/custom_dialog_bg">

<TextView
    android:id="@+id/txtDiaTitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/app_dialog_title"
    android:textColor="@color/black"
    android:textStyle="bold"
    android:gravity="center"
    android:padding="8dp"
    android:textAppearance="@android:style/TextAppearance.Medium"/>

<TextView
    android:id="@+id/txtDiaMsg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:padding="6dp"
    android:layout_gravity="center"
    android:layout_marginBottom="10dp"
    android:text="@string/app_dialog_desc"
    android:textColor="@color/black"
    android:textSize="12sp"/>

<View
    android:layout_width="match_parent"
    android:layout_height="1dip"
    android:background="@color/alarm_color"
    />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/yes"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/yes"
        android:textColor="#0C76EE"
        android:textStyle="bold"
        android:padding="5dp"
        android:clickable="true"
        android:layout_margin="5dp" />

    <View
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:background="@color/alarm_color"
        />

    <TextView
        android:id="@+id/no"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/no"
        android:textColor="#0C76EE"
        android:textStyle="bold"
        android:padding="5dp"
        android:clickable="true"
        android:layout_margin="5dp" />

    </LinearLayout>

</LinearLayout>

任何想法?
2个回答

8

您做得很好。但是您需要为对话框使用透明主题,或将对话框的背景窗口设置为透明。像这样:

dialog.getWindow().setBackgroundDrawable(new       ColorDrawable(android.graphics.Color.TRANSPARENT));

或者使用此链接


0

你能试一下下面的代码吗?

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="@android:color/white" />

    <corners android:radius="10dip" />

    <stroke
        android:width="1dp"
        android:color="@android:color/white" />

</shape>

希望这能对你有所帮助。

@UjjwalJha,请查看https://dev59.com/4GQo5IYBdhLWcg3wUN3Y#16161658。 - Hiren Patel
当我查看我们的Android Studio预览时,既显示先前的代码,也显示新的代码布局良好。 但是当我将此可绘制对象应用于我们的布局并进行检查时,就会出现这个问题。您能检查一下我的XML布局代码吗? - Ujjwal Jha
@UjjwalJha,让我检查一下然后告诉你。 - Hiren Patel
我猜你从未检查过。 - Denny
我笑了。 - Michael

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