{"id":4353,"date":"2021-07-19T14:14:09","date_gmt":"2021-07-19T06:14:09","guid":{"rendered":"http:\/\/122.152.205.50\/wordpress\/?p=4353"},"modified":"2022-01-18T11:29:12","modified_gmt":"2022-01-18T03:29:12","slug":"dialog%e5%b8%b8%e8%a7%81%e5%bc%82%e5%b8%b8","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=4353","title":{"rendered":"Dialog\u5e38\u89c1\u5f02\u5e38"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_16 counter-hierarchy counter-decimal ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" style=\"display: none;\"><i class=\"ez-toc-glyphicon ez-toc-icon-toggle\"><\/i><\/a><\/span><\/div>\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4353\/#%E5%BC%82%E5%B8%B81-%E9%80%80%E5%87%BA%E9%A1%B5%E9%9D%A2%E6%9C%AA%E5%8F%8A%E6%97%B6%E5%85%B3%E9%97%AD%E5%AF%B9%E8%AF%9D%E6%A1%86\" title=\"\u5f02\u5e381-\u9000\u51fa\u9875\u9762\u672a\u53ca\u65f6\u5173\u95ed\u5bf9\u8bdd\u6846\">\u5f02\u5e381-\u9000\u51fa\u9875\u9762\u672a\u53ca\u65f6\u5173\u95ed\u5bf9\u8bdd\u6846<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4353\/#%E5%BC%82%E5%B8%B82-%E8%AE%BE%E7%BD%AE%E5%AE%BD%E9%AB%98%E6%97%A0%E6%95%88\" title=\"\u5f02\u5e382-\u8bbe\u7f6e\u5bbd\u9ad8\u65e0\u6548\">\u5f02\u5e382-\u8bbe\u7f6e\u5bbd\u9ad8\u65e0\u6548<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4353\/#%E5%BC%82%E5%B8%B83-Unable_to_add_window_-_token_null_is_not_valid_is_your_activity_running\" title=\"\u5f02\u5e383-Unable to add window &#8212; token null is not valid; is your activity running?\">\u5f02\u5e383-Unable to add window &#8212; token null is not valid; is your activity running?<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=4353\/#%E5%BC%82%E5%B8%B84-Dialog%E5%B8%83%E5%B1%80%E9%AB%98%E5%BA%A6%E8%A2%AB%E6%84%8F%E5%A4%96%E7%9A%84match_parent\" title=\"\u5f02\u5e384-Dialog\u5e03\u5c40\u9ad8\u5ea6\u88ab\u610f\u5916\u7684match_parent\">\u5f02\u5e384-Dialog\u5e03\u5c40\u9ad8\u5ea6\u88ab\u610f\u5916\u7684match_parent<\/a><\/li><\/ul><\/nav><\/div>\n<h4><span class=\"ez-toc-section\" id=\"%E5%BC%82%E5%B8%B81-%E9%80%80%E5%87%BA%E9%A1%B5%E9%9D%A2%E6%9C%AA%E5%8F%8A%E6%97%B6%E5%85%B3%E9%97%AD%E5%AF%B9%E8%AF%9D%E6%A1%86\"><\/span>\u5f02\u5e381-\u9000\u51fa\u9875\u9762\u672a\u53ca\u65f6\u5173\u95ed\u5bf9\u8bdd\u6846<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><code>android.view.WindowLeaked: Activity com.example.netlib.activity.DemoHomeActivity has leaked windowDecorView@6891f75[DemoHomeActivity] that was originally added here<\/code><br \/>\n\u76f8\u5173\u94fe\u63a5\uff1a<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/pbm863521\/article\/details\/78656089\">https:\/\/blog.csdn.net\/pbm863521\/article\/details\/78656089<\/a><\/p>\n<ul>\n<li>\u9519\u8bef\u539f\u56e0<\/li>\n<\/ul>\n<p>\u662f\u56e0\u4e3aactivity\u4e2d\u7684Dialog\u3001PopupWindow\u4e0d\u80fd\u8131\u79bbactivity\u800c\u5355\u72ec\u5b58\u5728\u3002\u5f53Dialog\u3001PopupWindow\u6b63\u5728\u663e\u793a\u7684\u65f6\u5019\u800c\u5b83\u4eec\u4f9d\u9644\u7684activity\u5374destroy\u4e86\uff0c\u5c31\u4f1a\u51fa\u73b0WindowLeaked\u5f02\u5e38\u3002<\/p>\n<ul>\n<li>\u89e3\u51b3\u529e\u6cd5<\/li>\n<\/ul>\n<p>\u5728finish \u67d0\u4e2aactivity\u4e4b\u524d\u8981\u786e\u4fdd\u4f9d\u9644\u4e8e\u5176\u4e0a\u7684Dialog\u3001PopupWindow\u5df2\u7ecfdismiss\u4e86<\/p>\n<pre><code class=\"language-java line-numbers\">@Override\n    protected void onDestroy() {\n        super.onDestroy();\n        if(progressDialog!=null&amp;&amp;progressDialog.isShowing()) {\n            progressDialog.dismiss();\n        }\n    }\n<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"%E5%BC%82%E5%B8%B82-%E8%AE%BE%E7%BD%AE%E5%AE%BD%E9%AB%98%E6%97%A0%E6%95%88\"><\/span>\u5f02\u5e382-\u8bbe\u7f6e\u5bbd\u9ad8\u65e0\u6548<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li>\u89e3\u51b3\u529e\u6cd5<br \/>\n\u65b9\u6cd51\uff1a<\/li>\n<\/ul>\n<pre><code class=\"language-java line-numbers\">\/\/\u8bbe\u7f6e\u7a97\u53e3\u7684\u5927\u5c0f\ndialog.getWindow().setLayout(300, 200);\n<\/code><\/pre>\n<p>\u65b9\u6cd52\uff1a<\/p>\n<pre><code class=\"language-java line-numbers\">WindowManager.LayoutParams params = dialog.getWindow().getAttributes();  \nparams.width = 300;  \nparams.height = 200;  \ndialog.getWindow().setAttributes(params); \n<\/code><\/pre>\n<p>\u65b9\u6cd53\uff1a<br \/>\n\u5728\u6839\u5e03\u5c40\u5957\u4e00\u5c42\u5e03\u5c40<\/p>\n<ul>\n<li>\u5f02\u5e38\u539f\u56e0<\/li>\n<\/ul>\n<p>\u53c2\u8003\u6211\u7684\u53e6\u4e00\u7bc7\u6587\u7ae0<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/xinyiworld.top\/wordpress\/?p=4422\">http:\/\/xinyiworld.top\/wordpress\/?p=4422<\/a><\/p>\n<p>\u56e0\u4e3aAlertDialog\u7684view\u662finflate\u65f6\u5e76\u4e0d\u77e5\u9053root\u662f\u54ea\u4e2a\uff0c\u6240\u4ee5\u6839\u5e03\u5c40\u7684layout\u4f1a\u5931\u6548\u3002<\/p>\n<h4>\u5f02\u5e383-Unable to add window -- token null is not valid; is your activity running?<\/h4>\n<p>\u5982\u679c\u5c31\u60f3\u4f7f\u7528application context\u6765\u6784\u9020Dialog\uff0c\u4e5f\u662f\u53ef\u4ee5\u7684\u3002\u53ea\u9700\u8981<\/p>\n<pre><code class=\"language-java line-numbers\">alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);\n<\/code><\/pre>\n<p>\u8fd9\u6837\u7684\u8bdd\u5c31\u53ef\u4ee5\u5728Application\u91cc\u5b9a\u4e49\u4e00\u4e2a\u5168\u5c40\u7684\u5355\u4f8b\u7684Dialog\u7528\u6765\u7f51\u7edc\u52a0\u8f7d\u4e86\uff01\u4e0d\u5fc5\u6bcf\u4e2a\u9875\u9762\u90fd\u8981\u53bb\u521b\u5efadialog\u3002<\/p>\n<h4><span class=\"ez-toc-section\" id=\"%E5%BC%82%E5%B8%B84-Dialog%E5%B8%83%E5%B1%80%E9%AB%98%E5%BA%A6%E8%A2%AB%E6%84%8F%E5%A4%96%E7%9A%84match_parent\"><\/span>\u5f02\u5e384-Dialog\u5e03\u5c40\u9ad8\u5ea6\u88ab\u610f\u5916\u7684match_parent<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>\u95ee\u9898\uff1a<br \/>\n\u5728RelativeLayout\u91cc\u8bbe\u7f6e<code>android:layout_alignParentBottom=\"true\"<\/code>\uff0c\u5bfc\u81f4Dialog\u5e03\u5c40\u7684\u9ad8\u5ea6match_parent\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a\u4f7f\u7528ConstraintLayout\u66ff\u4ee3RelativeLayout<\/p>\n<button class=\"simplefavorite-button\" data-postid=\"4353\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 \u5f02\u5e381-\u9000\u51fa\u9875\u9762\u672a\u53ca\u65f6\u5173\u95ed\u5bf9\u8bdd\u6846\u5f02\u5e382-\u8bbe\u7f6e\u5bbd\u9ad8\u65e0\u6548\u5f02\u5e383-Unable to add win [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[172],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/4353"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4353"}],"version-history":[{"count":12,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/4353\/revisions"}],"predecessor-version":[{"id":5907,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/4353\/revisions\/5907"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4353"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}