第一种: 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();
效果图如下: