AlertDialog自定义对话框显示黑色边框

第一种:    AlertDialog自定义对话框显示黑色边框问题

原代码:

显示效果如下:

然后在 对话框布局文件的跟布局中设置了android:background="#00000000" 后的效果如下图:

显然这不是我想要的效果,最终解决办法如下

 

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this,AlertDialog.THEME_HOLO_LIGHT);
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.popupwindow01, null);
builder.setView(view);
dialog1 = builder.show();
加了一句代码(AlertDialog.THEME_HOLO_LIGHT)
最终的显示效果如下图:

第二种:自定义对话框显示黑色边框问题

1,布局文件 addshare_dialog.xml 代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#00000000"
    >
    <LinearLayout
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_gravity="center"
        android:background="@drawable/shape_dialog_background"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/addShare"
            android:textSize="20dp"
            android:layout_marginTop="10dp"/>

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

        <EditText
            android:id="@+id/et_shareAccounts"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/addShareHint"
            android:layout_margin="10dp"
            />

        <Button
            android:id="@+id/btn_shareButton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/share"
            android:background="@drawable/shape_btn_background"
            android:padding="10dp"
            android:layout_margin="10dp"
            />
    </LinearLayout>

    <ImageView
        android:id="@+id/tv_closeShare"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:src="@mipmap/close_dialog"
        android:layout_gravity="center"/>

</LinearLayout>

2 , drawable文件 

shape_dialog_background.xml 代码 :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:topLeftRadius="6dp"
        android:topRightRadius="6dp"
        android:bottomRightRadius="6dp"
        android:bottomLeftRadius="6dp"/>
    <solid android:color="@color/white"></solid>
</shape>

shape_btn_background.xml 代码:

 

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:topLeftRadius="6dp"
        android:topRightRadius="6dp"
        android:bottomRightRadius="6dp"
        android:bottomLeftRadius="6dp"/>
    <solid android:color="@color/light_blue"></solid>
</shape>

activity文件代码:

Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.addshare_dialog);
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
dialog.setCanceledOnTouchOutside(false);
dialog.show();

效果图如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值