{"id":7579,"date":"2023-10-18T12:01:25","date_gmt":"2023-10-18T04:01:25","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=7579"},"modified":"2023-10-18T12:01:25","modified_gmt":"2023-10-18T04:01:25","slug":"android-alertdialog%e5%b0%81%e8%a3%85%e6%93%8d%e4%bd%9c%e6%b5%81%e7%a8%8b%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2023\/10\/18\/android-alertdialog%e5%b0%81%e8%a3%85%e6%93%8d%e4%bd%9c%e6%b5%81%e7%a8%8b%e4%bb%8b%e7%bb%8d\/","title":{"rendered":"android alertdialog\u5c01\u88c5\u64cd\u4f5c\u6d41\u7a0b\u4ecb\u7ecd"},"content":{"rendered":"

AlertDialog\u662fAndroid\u5f00\u53d1\u4e2d\u5e38\u7528\u7684\u4e00\u79cd\u5f39\u7a97\u63a7\u4ef6\uff0c\u5b83\u53ef\u4ee5\u7528\u4e8e\u63d0\u793a\u7528\u6237\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u64cd\u4f5c\uff0c\u6216\u8005\u5c55\u793a\u4e00\u4e9b\u4fe1\u606f\u3002\u5728Android\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u4f7f\u7528AlertDialog\u6765\u4e0e\u7528\u6237\u8fdb\u884c\u4ea4\u4e92\u3002\u672c\u6587\u5c06\u4ecb\u7ecdAlertDialog\u7684\u5c01\u88c5\u539f\u7406\u548c\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n

AlertDialog\u7684\u5c01\u88c5\u539f\u7406<\/p>\n

AlertDialog\u7684\u5c01\u88c5\u4e3b\u8981\u662f\u901a\u8fc7\u81ea\u5b9a\u4e49Dialog\u7c7b\u6765\u5b9e\u73b0\u3002\u5728Android\u4e2d\uff0cDialog\u662f\u4e00\u4e2a\u62bd\u8c61\u7c7b\uff0c\u6211\u4eec\u65e0\u6cd5\u76f4\u63a5\u4f7f\u7528\u5b83\uff0c\u56e0\u6b64\u9700\u8981\u81ea\u5b9a\u4e49\u4e00\u4e2a\u7c7b\u6765\u7ee7\u627fDialog\uff0c\u5e76\u5728\u8be5\u7c7b\u4e2d\u5b9e\u73b0Alert<\/p>\n

<\/figure>\n<\/p>\n

Dialog\u7684\u76f8\u5173\u529f\u80fd\u3002<\/p>\n

\u5728\u81ea\u5b9a\u4e49Dialog\u7c7b\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e9b\u5e03\u5c40\u6587\u4ef6\u548c\u53d8\u91cf\uff0c\u7528\u4e8e\u63a7\u5236AlertDialog\u7684\u5916\u89c2\u548c\u884c\u4e3a\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u5e03\u5c40\u6587\u4ef6\u6765\u8bbe\u7f6eAlertDialog\u7684\u6837\u5f0f\uff0c\u6216\u8005\u5b9a\u4e49\u4e00\u4e9b\u53d8\u91cf\u6765\u63a7\u5236AlertDialog\u4e2d\u7684\u6309\u94ae\u884c\u4e3a\u3002<\/p>\n

\u5728\u81ea\u5b9a\u4e49Dialog\u7c7b\u4e2d\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u5b9e\u73b0\u4e00\u4e9b\u65b9\u6cd5\u6765\u63a7\u5236AlertDialog\u7684\u663e\u793a\u548c\u9690\u85cf\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2ashow()\u65b9\u6cd5\u6765\u663e\u793aAlertDialog\uff0c\u6216\u8005\u5b9e\u73b0\u4e00\u4e2adismiss()\u65b9\u6cd5\u6765\u9690\u85cfAlertDialog\u3002<\/p>\n

AlertDialog\u7684\u5c01\u88c5\u8be6\u7ec6\u4ecb\u7ecd<\/p>\n

AlertDialog\u7684\u5c01\u88c5\u9700\u8981\u5b9e\u73b0\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<\/p>\n

1. \u5b9a\u4e49AlertDialog\u7684\u5e03\u5c40\u6587\u4ef6<\/p>\n

\u5728\u5e03\u5c40\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49AlertDialog\u7684\u6837\u5f0f\u548c\u63a7\u4ef6\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2aTextView\u6765\u663e\u793aAlertDialog\u7684\u63d0\u793a\u4fe1\u606f\uff0c\u6216\u8005\u5b9a\u4e49\u4e00\u4e2aButton\u6765\u63a7\u5236AlertDialog\u7684\u884c\u4e3a\u3002<\/p>\n

2. \u5b9a\u4e49AlertDialog\u7684\u53d8\u91cf<\/p>\n

\u5728\u81ea\u5b9a\u4e49Dialog\u7c7b\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e9b\u53d8\u91cf\u6765\u63a7\u5236AlertDialog\u7684\u5916\u89c2\u548c\u884c\u4e3a\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9aandroid xui<\/a>\u4e49\u4e00\u4e2a\u53d8\u91cf\u6765\u4fdd\u5b58AlertDialog\u7684\u63d0\u793a\u4fe1\u606f\uff0c\u6216\u8005\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\u6765\u4fdd\u5b58AlertDialog\u7684\u6309\u94ae\u884c\u4e3a\u3002<\/p>\n

3. \u5b9e\u73b0AlertDialog\u7684\u6784\u9020\u65b9\u6cd5<\/p>\n

\u5728\u6784\u9020\u65b9\u6cd5\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u521d\u59cb\u5316AlertDialog\u7684\u5e03\u5c40\u6587\u4ef6\u548c\u53d8\u91cf\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528LayoutInflater\u6765\u52a0\u8f7d\u5e03\u5c40\u6587\u4ef6\uff0c\u6216\u8005\u4f7f\u7528findViewById()\u65b9\u6cd5\u6765\u83b7\u53d6\u5e03\u5c40\u6587\u4ef6\u4e2d\u7684\u63a7\u4ef6\u3002<\/p>\n

4. \u5b9e\u73b0AlertDialog\u7684show()\u65b9\u6cd5<\/p>\n

\u5728show()\u65b9\u6cd5\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u663e\u793aAlertDialog\uff0c\u5e76\u8bbe\u7f6e\u5b83\u7684\u6837\u5f0f\u548c\u884c\u4e3a\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528setConteandroid\u7cfb\u7edf\u5f00\u53d1\u4f18\u70b9<\/a>ntView()\u65b9\u6cd5\u6765\u8bbe\u7f6eAlertDialog\u7684\u5e03\u5c40\u6587\u4ef6\uff0c\u6216\u8005\u4f7f\u7528setCancelable()\u65b9\u6cd5\u6765\u63a7\u5236AlertDialog\u662f\u5426\u53ef\u4ee5\u53d6\u6d88\u3002<\/p>\n

5. \u5b9e\u73b0AlertDialog\u7684dismiss()\u65b9\u6cd5<\/p>\n

\u5728dismiss()\u65b9\u6cd5\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u9690\u85cfAlertDialog\uff0c\u5e76\u6e05\u9664\u5b83\u7684\u6837\u5f0f\u548c\u884c\u4e3a\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528dismiss()\u65b9\u6cd5\u6765\u9690\u85cfAlertDialog\uff0c\u6216\u8005\u4f7f\u7528setContentView(null)\u65b9\u6cd5\u6765\u6e05\u9664AlertDialog\u7684\u5e03\u5c40\u6587\u4ef6\u3002<\/p>\n

\u4ee5\u4e0a\u5c31\u662fAlertDialog\u7684\u5c01\u88c5\u539f\u7406\u548c\u8be6\u7ec6\u4ecb\u7ecd\u3002\u901a\u8fc7\u81ea\u5b9a\u4e49Dialog\u7c7b\u548c\u5b9e\u73b0\u76f8\u5173\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5c01\u88c5\u4e00\u4e2aAlertDialog\uff0c\u5e76\u5728Android\u5e94\u7528\u4e2d\u4f7f\u7528\u5b83\u6765\u4e0e\u7528\u6237\u8fdb\u884c\u4ea4\u4e92\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

AlertDialog\u662fAndroid\u5f00\u53d1\u4e2d\u5e38\u7528\u7684\u4e00\u79cd\u5f39\u7a97\u63a7\u4ef6\uff0c\u5b83\u53ef\u4ee5\u7528\u4e8e\u63d0\u793a\u7528\u6237\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u64cd\u4f5c\uff0c\u6216\u8005\u5c55\u793a\u4e00\u4e9b\u4fe1\u606f\u3002\u5728Android\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u4f7f\u7528AlertDialog\u6765\u4e0e\u7528\u6237\u8fdb\u884c\u4ea4\u4e92\u3002<\/p>\n","protected":false},"author":22,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1844,7453,1395,41,13258],"topic":[],"class_list":["post-7579","post","type-post","status-publish","format-standard","hentry","category-kaifaapp","tag-ios-app","tag-vue-h5apk","tag-1395","tag-41","tag-13258"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/7579","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=7579"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/7579\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=7579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=7579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=7579"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=7579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}