看代码:

public class MainActivity extends AppCompatActivity {

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
View view1 = inflater.inflate(R.layout.alert, (ViewGroup) findViewById(R.id.alertdialog));
builder.setView(view1);
final AlertDialog dialog = builder.show();
view1.findViewById(R.id.btn_invent).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.e("tag", "onClick: "+"点击取消" );
dialog.dismiss();
}
}); }
});
}
} 要取消dialog先要获取dialog,再dismiss(),直接dismiss()是没有用的;
demo下载地址:https://github.com/renjiemei1225/AlertDialogTest2

android 自定义alertdialog和取消dialog的更多相关文章

  1. Android 自定义AlertDialog退出对话框

    Android 自定义AlertDialog退出对话框 转 https://blog.csdn.net/wkh11/article/details/53081634在项目中很多时候会出现点击返回键出现 ...

  2. Android 自定义AlertDialog的实现

    Android默认的AlertDialog太单调,我们可以通过继承原生的Dialog来实现自定义的Dialog. 本文的自定义Dialog和原生的AlertDialog的创建方式类似,通过一个静态Bu ...

  3. Android 自定义AlertDialog(退出提示框)

    有时候我们需要在游戏或应用中用一些符合我们样式的提示框(AlertDialog) 以下是我在开发一个小游戏中总结出来的.希望对大家有用. 先上效果图: 下面是用到的背景图或按钮的图片 经过查找资料和参 ...

  4. Android自定义AlertDialog

    常见的一种方法: [html] view plaincopyprint? AlertDialog.Builder builder; AlertDialog alertDialog; LayoutInf ...

  5. android 自定义AlertDialog(一段)

    java: final AlertDialog dialog = new AlertDialog.Builder(mContext) .create(); dialog.setCancelable(f ...

  6. Android 自定义AlertDialog的写法和弹出软键盘和覆盖状态栏

    private void showMyDialog(int layoutId){ AlertDialog myDialog = new AlertDialog.Builder(context).cre ...

  7. android 自定义AlertDialog

    xml: alter_dialog_two <?xml version="1.0" encoding="utf-8"?> <LinearLay ...

  8. Android 自定义带回调的Dialog 及EditText相关

      import android.app.Activity; import android.content.Context; import android.text.Editable; import ...

  9. Android之自定义AlertDialog和PopupWindow实现(仿微信Dialog)

    我们知道,在很多时候,我们都不用Android内置的一些控件,而是自己自定义一些自己想要的控件,这样显得界面更美观. 今天主要是讲自定义AlertDialog和popupWindow的使用,在很多需求 ...

随机推荐

  1. UICollectionView的使用

    感谢下面文章作者的无私奉献 基础用法: http://www.cnblogs.com/ios8/p/iOS-UICollectionView.html http://my.oschina.net/jo ...

  2. vs2010 安装mvc3

    下载链接如下:MVC 3安装包:http://www.microsoft.com/downloads/zh-cn/details.aspx?familyid=d2928bc1-f48c-4e95-a0 ...

  3. Spring JDBC实现查询

    1 db.properties jdbc.user=root jdbc.password=920614 jdbc.driverClass=com.mysql.jdbc.Driver jdbc.jdbc ...

  4. MyBatis与Hibernate的比较

    Hibernate 与Mybatis都是流行的持久层开发框架,但Hibernate开发社区相对多热闹些,支持的工具也多,更新也快,当前最高版本4.1.8.而Mybatis相对平静,工具较少,当前最高版 ...

  5. PHPWord

    PHPWord中文乱码 我在 使用PHPWord$section->addText(),输出中文是遇到乱码,PHPWord 中文乱码解决如下: 第一步:打开phpword/Section.php ...

  6. Pychram如何导入Django项目

    最近在学Django,用GitHub来保存项目.但当从GitHub中clone出来后,Pycharm怎么来运行项目呢? 首先要对项目进行设置,使其能支持Django,具体设置如下: 在Pycharm中 ...

  7. 关于使用TP-Link桥接小米路由器

    家里因为有个小卧室,小卧室的写字台上面放了一台台式电脑,而我又不想用台式电脑牵一条长线到客厅的网口或者路由器上面,因为太麻烦,所以我使用了TPLink的无线USB插在了我的主机USB上,略去TPLIN ...

  8. Eclipse svn插件包

    SVN插件下载地址及更新地址,你根据需要选择你需要的版本.现在最新是1.8.x Links for 1.8.x Release: Eclipse update site URL: http://sub ...

  9. Bash Shell 获取进程 PID

    转载地址:http://weyo.me/pages/techs/linux-get-pid/ 导读 Linux 的交互式 Shell 与 Shell 脚本存在一定的差异,主要是由于后者存在一个独立的运 ...

  10. linux命令按文件内容查找文件

    [root@hn web]# find /app/code/hzg/web/ -type f -name "*.php" | xargs grep "slog"