有时候dialog不能满足我们的UI 需求,因此需要自己定义dialog的界面 ,此时我们可以用
setContentView(view) 这个方法来实现 ,废话少说,直接上代码
1 导入包
import androidx.appcompat.app.AlertDialog;
2 创建dialog
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
AlertDialog alertDialog = builder.create();
alertDialog.show();//注意:必须在window.setContentView之前show
View view = getDialogView();
alertDialog.setContentView(view);
private View getDialogView() {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.loading_dialog, null);// 得到加载view
// main.xml中的ImageView
ImageView spaceshipImage = (ImageView) view.findViewById(R.id.img);
TextView tipTextView = (TextView) view.findViewById(R.id.tipTextView);// 提示文字
// 加载动画
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
mContext, R.anim.loadin