android alertdialog布局 dialog布局
发布日期:2021-06-29 15:21:53
浏览次数:3
分类:技术文章
本文共 812 字,大约阅读时间需要 2 分钟。
昨天做项目的时候,需要弹出一个dialog,并且在在上面放一个view和两个button,于是搜资料android dialog上的布局,发现dialog 和 activity 的布局方法如出一辙,下面贴上代码: AlertDialog: Java代码 AlertDialog dialog = new AlertDialog.Builder(BitmapOperatorActivity.this).create(); Java代码 //Dialog 的话是 Dialog dialog = new Dialog(BitmapOperatorActivity.this); Java代码 dialog.show(); dialog.setContentView(R.layout.alertdialog_layout); MyDialogView dialogView = (MyDialogView) dialog.findViewById(R.id.dialogview); Log.i("shuai", "dialog-->" + dialogView); dialogView.setBitmap(bitmap); 要特别注意的是,dialog.show(),一定要放在dialog.setContentView()的前面 否则的话会报下述错误: Java代码 android.util.AndroidRuntimeException: requestFeature() must be called before adding content 也就是必须先show,才能setContentView 如果要得到这个布局上的控件的话,就用 dialog.findViewById() 特别声明:是dialog.findViewById() 否则的话,运行时会报错误 注:仅是个人解决的方法,仅供参考,勿扔板砖,谢谢转载地址:https://codegg.blog.csdn.net/article/details/19902155 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年04月04日 04时12分19秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
open-falcon template继承与覆盖 注意事项
2019-04-29
Docker stack task: non-zero exit (137) OOM
2019-04-29
Nginx Docker容器 获取客户端真实IP地址问题
2019-04-29
ssh-copy-id 卡住问题
2019-04-29
Random SecureRandom 随机数生成阻塞问题
2019-04-29
tomcat8.5.15 apr模式运行 配置
2019-04-29
Linux命令笔记
2019-04-29
ElasticSearch5.4.3 环境搭建 2017 (1-单节点模式/开发模式)
2019-04-29
ElasticSearch5.4.3 环境搭建 2017 (2-集群搭建)
2019-04-29
Mysql 使用全文索引
2019-04-29
ElasticSearch5.4.3 环境搭建 2017 (6-IK中文分词插件)
2019-04-29