android各种提示Dialog 弹出框

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

完整开源地址:https://docs.qq.com/doc/DSkNLaERkbnFoS0ZF

} else {

messageTv.setText(message);

messageTv.setVisibility(View.VISIBLE);

}

return dialog;

}

public static Dialog getCustomDialog(final Activity activity, View view, boolean dismissTouchOutside,

boolean cancelable, int theme) {

//Dialog dialog = theme > 0 ? new FullScreenDialogHUD(activity, theme)

// : new Dialog(activity, R.style.Dialog_FullScreen);

Dialog dialog = new Dialog(activity, R.style.Dialog_FullScreen);

dialog.setContentView(view);

dialog.setCancelable(cancelable);

dialog.setCanceledOnTouchOutside(dismissTouchOutside);

if (!cancelable) {

dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

@Override

public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {

dialog.dismiss();

activity.finish();

}

return false;

}

});

}

return dialog;

}

public static Dialog getOneButtonDialog(final Activity activity, String content,

boolean dismissTouchOutside, boolean cancelable,

DialogInterface.OnClickListener confirmOnClickListener) {

Dialog dialog = new AlertDialog.Builder(activity)

.setPositiveButton(R.string.confirm, confirmOnClickListener)

.setCancelable(cancelable)

.setMessage(content)

.create();

dialog.setCanceledOnTouchOutside(dismissTouchOutside);

if (!cancelable) {

dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

@Override

public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {

dialog.dismiss();

activity.finish();

}

return false;

}

});

}

return dialog;

}

public static Dialog getButtonsDialog(Activity activity, int resId,

DialogInterface.OnClickListener confirmOnClickListener) {

return getButtonsDialog(activity, activity.getString(resId), true, true, confirmOnClickListener,

null);

}

public static Dialog getButtonsDialog(Activity activity, String content,

DialogInterface.OnClickListener confirmOnClickListener) {

return getButtonsDialog(activity, content, true, true, confirmOnClickListener, null);

}

public static Dialog getButtonsDialog(Activity activity, String content, boolean dismissTouchOutside,

boolean cancelable, DialogInterface.OnClickListener confirmOnClickListener,

DialogInterface.OnClickListener cancelOnClickListener) {

Dialog dialog = new AlertDialog.Builder(activity)

.setNegativeButton(R.string.cancel, cancelOnClickListener)

.setPositiveButton(R.string.confirm, confirmOnClickListener)

.setCancelable(cancelable)

.setMessage(content)

.create();

dialog.setCanceledOnTouchOutside(dismissTouchOutside);

return dialog;

}

progress_hud.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:orientation=“vertical”

  • 12
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的 Android 代码示例,演示如何在按钮点击时弹出提示框: 1. 在你的 XML 布局文件中添加一个按钮控件: ```xml <Button android:id="@+id/my_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点击我弹出提示框" /> ``` 2. 在你的 Java 代码中获取按钮控件,然后为它设置点击事件监听器: ```java Button myButton = findViewById(R.id.my_button); myButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 在这里编写弹出提示框的代码 } }); ``` 3. 在点击事件监听器中,使用 `AlertDialog.Builder` 类创建一个提示框,并设置标题、消息和按钮: ```java AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("提示"); builder.setMessage("确定要执行这个操作吗?"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 在这里编写“确定”按钮被点击时的代码 } }); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 在这里编写“取消”按钮被点击时的代码 } }); AlertDialog dialog = builder.create(); dialog.show(); ``` 这样,当用户点击按钮时,就会弹出一个提示框,询问用户是否要执行某项操作。用户可以选择“确定”或“取消”按钮。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值