1. 程式人生 > >Android 如何讓Dialog實現背景透明

Android 如何讓Dialog實現背景透明

View inflate = LayoutInflater.from(context).inflate(R.layout.qrcode, null);
ImageView qrcode = (ImageView) inflate.findViewById(R.id.iv_qrcode);
ImageView guanbi = (ImageView) inflate.findViewById(R.id.iv_guanbi);
final Dialog dialog = new AlertDialog
        .Builder(context)
        .setView(inflate)
        .show();

dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent
); Glide.with(context).load(list.get(position).getDwhat()).into(qrcode); Animation animation = AnimationUtils.loadAnimation(context, R.anim.scale); inflate.setAnimation(animation); animation.start();
最關鍵的一行程式碼佈局檔案
<?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"
> <ImageViewandroid:id="@+id/iv_qrcode" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher" /> <View android:layout_width="match_parent"
android:layout_height="80dp" android:background="#00000000"
/> <ImageViewandroid:id="@+id/iv_guanbi" android:layout_width="40dp" android:layout_height="40dp" android:background="@android:color/transparent" android:layout_gravity="center" android:src="@drawable/guanbi" /> </LinearLayout>
參考連結:https://blog.csdn.net/aaren_jiang/article/details/12993343注意:要用Dialog去接收