自定义弹窗类——Android 透明圆角弹窗
import android.content.Context; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.view.Window; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; public class MySetDailog extends AlertDialog { TextView tvmydailog01; TextView tvmydailog02; ImageView ivdailog; public MySetDailog(@NonNull Context context ) { super(context); setCanceledOnTouchOutside(true);//点击其他区域时 true 关闭弹窗 false 不关闭弹窗 tvmydailog01 = findViewById(R.id.tv_mydailog01); tvmydailog02 = findViewById(R.id.tv_mydailog02); ivdailog = findViewById(R.id.iv_mydailog); } /*设置图片接口*/ public void setImageResource(int resId){ ivdailog.setImageResource(resId); } /*设置文字接口*/ public void setText01(String str){ tvmydailog01.setText(str); } public void setText02(String str){ tvmydailog02.setText(str); } /*设置文字颜色接口*/ public void setColor01(int color01){ tvmydailog01.setTextColor(color01); } public void setColor02(int color02){ tvmydailog02.setTextColor(color02); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog_mydailog);//加载布局 //设置透明背景 Window window = getWindow(); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); } }
xml布局文件
<&#63;xml version="1.0" encoding="utf-8"&#63;>
调用
MySetDailog mySetDailog = new MySetDailog(BindActivity.this); mySetDailog.show();
到此这篇关于Android实现圆角弹框功能的文章就介绍到这了,更多相关android圆角弹框内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!