{"id":16202,"date":"2026-03-03T10:49:51","date_gmt":"2026-03-03T02:49:51","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202"},"modified":"2026-03-13T11:40:56","modified_gmt":"2026-03-13T03:40:56","slug":"%e4%b8%80%e3%80%81compose%e7%bc%96%e7%a8%8b%e6%80%9d%e6%83%b3","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202","title":{"rendered":"\u4e00\u3001Compose\u7f16\u7a0b\u601d\u60f3"},"content":{"rendered":"<p><a href=\"https:\/\/developer.android.google.cn\/develop\/ui\/compose\/mental-model?hl=zh-cn\">https:\/\/developer.android.google.cn\/develop\/ui\/compose\/mental-model?hl=zh-cn<\/a><\/p>\n<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-1\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#%E4%B8%80%E3%80%81%E5%9F%BA%E6%9C%AC%E6%80%9D%E6%83%B3\" title=\"\u4e00\u3001\u57fa\u672c\u601d\u60f3\">\u4e00\u3001\u57fa\u672c\u601d\u60f3<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#%F0%9F%92%A1_%E6%A0%B8%E5%BF%83%E6%80%9D%E6%83%B3%EF%BC%9A%E5%A3%B0%E6%98%8E%E6%80%A7UI\" title=\"\ud83d\udca1 \u6838\u5fc3\u601d\u60f3\uff1a\u58f0\u660e\u6027UI\">\ud83d\udca1 \u6838\u5fc3\u601d\u60f3\uff1a\u58f0\u660e\u6027UI<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#%F0%9F%A7%B1_%E5%9F%BA%E6%9C%AC%E6%9E%84%E5%BB%BA%E5%8D%95%E5%85%83%EF%BC%9A%E5%8F%AF%E7%BB%84%E5%90%88%E5%87%BD%E6%95%B0\" title=\"\ud83e\uddf1 \u57fa\u672c\u6784\u5efa\u5355\u5143\uff1a\u53ef\u7ec4\u5408\u51fd\u6570\">\ud83e\uddf1 \u57fa\u672c\u6784\u5efa\u5355\u5143\uff1a\u53ef\u7ec4\u5408\u51fd\u6570<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#%F0%9F%94%84_%E5%8A%A8%E6%80%81%E5%86%85%E5%AE%B9%E4%B8%8EKotlin%E7%9A%84%E5%8A%9B%E9%87%8F\" title=\"\ud83d\udd04 \u52a8\u6001\u5185\u5bb9\u4e0eKotlin\u7684\u529b\u91cf\">\ud83d\udd04 \u52a8\u6001\u5185\u5bb9\u4e0eKotlin\u7684\u529b\u91cf<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-5\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#%E2%9A%99%EF%B8%8F_%E6%A0%B8%E5%BF%83%E6%9C%BA%E5%88%B6%EF%BC%9A%E6%99%BA%E8%83%BD%E9%87%8D%E7%BB%84\" title=\"\u2699\ufe0f \u6838\u5fc3\u673a\u5236\uff1a\u667a\u80fd\u91cd\u7ec4\">\u2699\ufe0f \u6838\u5fc3\u673a\u5236\uff1a\u667a\u80fd\u91cd\u7ec4<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-6\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#%E2%9A%A0%EF%B8%8F_%E6%9C%80%E9%87%8D%E8%A6%81%E7%9A%84%E8%A7%84%E5%88%99%EF%BC%9A%E6%97%A0%E5%89%AF%E4%BD%9C%E7%94%A8\" title=\"\u26a0\ufe0f \u6700\u91cd\u8981\u7684\u89c4\u5219\uff1a\u65e0\u526f\u4f5c\u7528\">\u26a0\ufe0f \u6700\u91cd\u8981\u7684\u89c4\u5219\uff1a\u65e0\u526f\u4f5c\u7528<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-7\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#%E2%9C%85_%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5%E4%B8%8E%E6%A8%A1%E5%BC%8F\" title=\"\u2705 \u6700\u4f73\u5b9e\u8df5\u4e0e\u6a21\u5f0f\">\u2705 \u6700\u4f73\u5b9e\u8df5\u4e0e\u6a21\u5f0f<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-8\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#%F0%9F%93%8C_%E6%80%BB%E7%BB%93%E8%A6%81%E7%82%B9\" title=\"\ud83d\udccc \u603b\u7ed3\u8981\u70b9\">\ud83d\udccc \u603b\u7ed3\u8981\u70b9<\/a><\/li><\/ul><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-9\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#%E4%BA%8C%E3%80%81Compose%E6%B3%A8%E8%A7%A3\" title=\"\u4e8c\u3001@Compose\u6ce8\u89e3\">\u4e8c\u3001@Compose\u6ce8\u89e3<\/a><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><ul class=\"ez-toc-list-level-3\"><li class=\"ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-10\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#%E4%B8%80%E5%8F%A5%E8%AF%9D%E7%90%86%E8%A7%A3\" title=\"\u4e00\u53e5\u8bdd\u7406\u89e3\">\u4e00\u53e5\u8bdd\u7406\u89e3<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-11\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#3%E4%B8%AA%E6%A0%B8%E5%BF%83%E7%82%B9\" title=\"3\u4e2a\u6838\u5fc3\u70b9\">3\u4e2a\u6838\u5fc3\u70b9<\/a><ul class=\"ez-toc-list-level-4\"><li class=\"ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-12\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#1_%E5%AE%83%E4%B8%8D%E6%98%AF%E6%99%AE%E9%80%9A%E5%87%BD%E6%95%B0\" title=\"1. \u5b83\u4e0d\u662f\u666e\u901a\u51fd\u6570\">1. \u5b83\u4e0d\u662f\u666e\u901a\u51fd\u6570<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-13\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#2_%E5%AE%83%E5%BF%85%E9%A1%BB%E8%A2%AB_Composable_%E5%87%BD%E6%95%B0%E8%B0%83%E7%94%A8\" title=\"2. \u5b83\u5fc5\u987b\u88ab @Composable \u51fd\u6570\u8c03\u7528\">2. \u5b83\u5fc5\u987b\u88ab @Composable \u51fd\u6570\u8c03\u7528<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-4\"><a class=\"ez-toc-link ez-toc-heading-14\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#3_%E5%AE%83%E5%8F%AF%E4%BB%A5%E8%87%AA%E5%8A%A8%E5%93%8D%E5%BA%94%E6%95%B0%E6%8D%AE%E5%8F%98%E5%8C%96\" title=\"3. \u5b83\u53ef\u4ee5\u81ea\u52a8\u54cd\u5e94\u6570\u636e\u53d8\u5316\">3. \u5b83\u53ef\u4ee5\u81ea\u52a8\u54cd\u5e94\u6570\u636e\u53d8\u5316<\/a><\/li><\/ul><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-15\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#%E8%AE%B0%E5%BF%86%E5%8F%A3%E8%AF%80\" title=\"\u8bb0\u5fc6\u53e3\u8bc0\">\u8bb0\u5fc6\u53e3\u8bc0<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-16\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#%E5%AF%B9%E6%AF%94%E7%90%86%E8%A7%A3\" title=\"\u5bf9\u6bd4\u7406\u89e3\">\u5bf9\u6bd4\u7406\u89e3<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-3\"><a class=\"ez-toc-link ez-toc-heading-17\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=16202\/#90_%E7%9A%84%E5%9C%BA%E6%99%AF%E4%BD%A0%E5%8F%AA%E9%9C%80%E8%A6%81%E7%9F%A5%E9%81%93%EF%BC%9A\" title=\"90% \u7684\u573a\u666f\u4f60\u53ea\u9700\u8981\u77e5\u9053\uff1a\">90% \u7684\u573a\u666f\u4f60\u53ea\u9700\u8981\u77e5\u9053\uff1a<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E4%B8%80%E3%80%81%E5%9F%BA%E6%9C%AC%E6%80%9D%E6%83%B3\"><\/span>\u4e00\u3001\u57fa\u672c\u601d\u60f3<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h3><span class=\"ez-toc-section\" id=\"%F0%9F%92%A1_%E6%A0%B8%E5%BF%83%E6%80%9D%E6%83%B3%EF%BC%9A%E5%A3%B0%E6%98%8E%E6%80%A7UI\"><\/span>\ud83d\udca1 \u6838\u5fc3\u601d\u60f3\uff1a\u58f0\u660e\u6027UI<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u5728\u4f20\u7edf\u7684<strong>\u547d\u4ee4\u5f0f<\/strong>UI\u4e2d\uff0c\u4f60\u9700\u8981\u624b\u52a8\u83b7\u53d6\u89c6\u56fe\u5bf9\u8c61\u5e76\u8c03\u7528\u5176\u65b9\u6cd5\uff08\u5982<code>setText()<\/code>\uff09\u6765\u66f4\u65b0\u754c\u9762\u3002\u8fd9\u4e0d\u4ec5\u7e41\u7410\uff0c\u8fd8\u5bb9\u6613\u5bfc\u81f4\u72b6\u6001\u4e0d\u4e00\u81f4\u3002<\/p>\n<p>Compose\u91c7\u7528\u7684\u662f<strong>\u58f0\u660e\u6027<\/strong>\u8303\u5f0f\u3002\u4f60\u53ea\u9700\u8981<strong>\u63cf\u8ff0\u754c\u9762\u5e94\u8be5\u5448\u73b0\u7684\u6837\u5b50<\/strong>\uff0c\u5b83\u5b8c\u5168\u7531<strong>\u72b6\u6001<\/strong>\u9a71\u52a8\u3002<\/p>\n<ul>\n<li><strong>UI = f(\u72b6\u6001)<\/strong>\uff1a\u754c\u9762\u662f\u72b6\u6001\u7684\u4e00\u4e2a\u51fd\u6570\u3002\u5f53\u72b6\u6001\u53d8\u5316\u65f6\uff0cCompose\u4f1a\u667a\u80fd\u5730<strong>\u91cd\u65b0\u6267\u884c<\/strong>\u53d7\u5f71\u54cd\u7684\u53ef\u7ec4\u5408\u51fd\u6570\uff0c\u5e76\u81ea\u52a8\u66f4\u65b0\u754c\u9762\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u88ab\u79f0\u4e3a<strong>\u91cd\u7ec4<\/strong>\u3002<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"%F0%9F%A7%B1_%E5%9F%BA%E6%9C%AC%E6%9E%84%E5%BB%BA%E5%8D%95%E5%85%83%EF%BC%9A%E5%8F%AF%E7%BB%84%E5%90%88%E5%87%BD%E6%95%B0\"><\/span>\ud83e\uddf1 \u57fa\u672c\u6784\u5efa\u5355\u5143\uff1a\u53ef\u7ec4\u5408\u51fd\u6570<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u53ef\u7ec4\u5408\u51fd\u6570\u662fCompose\u4e2d\u6700\u57fa\u7840\u7684\u5355\u5143\uff0c\u5b83\u6709\u4ee5\u4e0b\u51e0\u4e2a\u91cd\u8981\u7279\u5f81\uff1a<\/p>\n<ul>\n<li><strong><code>@Composable<\/code> \u6ce8\u89e3<\/strong>\uff1a\u6240\u6709\u53ef\u7ec4\u5408\u51fd\u6570\u90fd\u5fc5\u987b\u6709\u6b64\u6ce8\u89e3\uff0c\u4ee5\u544a\u77e5\u7f16\u8bd1\u5668\u5c06\u5176\u8f6c\u6362\u4e3a\u754c\u9762\u3002<\/li>\n<li><strong>\u63a5\u53d7\u6570\u636e\uff0c\u53d1\u51faUI<\/strong>\uff1a\u51fd\u6570\u63a5\u6536\u6570\u636e\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u901a\u8fc7\u8c03\u7528\u5176\u4ed6\u53ef\u7ec4\u5408\u51fd\u6570\u6765\u751f\u6210\u754c\u9762\u3002<\/li>\n<li><strong>\u65e0\u8fd4\u56de\u503c<\/strong>\uff1a\u5b83\u4e0d\u8fd4\u56de\u4efb\u4f55\u5bf9\u8c61\uff0c\u800c\u662f\u63cf\u8ff0\u4e86\u76ee\u6807\u5c4f\u5e55\u7684\u72b6\u6001\u3002<\/li>\n<li><strong>\u5feb\u901f\u3001\u5e42\u7b49\u3001\u65e0\u526f\u4f5c\u7528<\/strong>\uff1a\u8fd9\u662f\u53ef\u7ec4\u5408\u51fd\u6570\u4e3a\u4e86\u652f\u6301\u9ad8\u6548\u91cd\u7ec4\u800c\u5fc5\u987b\u9075\u5faa\u7684\u91cd\u8981\u5c5e\u6027\u3002\u540e\u9762\u4f1a\u8be6\u7ec6\u89e3\u91ca\u3002<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"%F0%9F%94%84_%E5%8A%A8%E6%80%81%E5%86%85%E5%AE%B9%E4%B8%8EKotlin%E7%9A%84%E5%8A%9B%E9%87%8F\"><\/span>\ud83d\udd04 \u52a8\u6001\u5185\u5bb9\u4e0eKotlin\u7684\u529b\u91cf<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u56e0\u4e3a\u53ef\u7ec4\u5408\u51fd\u6570\u662f\u7528Kotlin\u7f16\u5199\u7684\uff0c\u6240\u4ee5\u5b83\u62e5\u6709\u4e86\u5e95\u5c42\u8bed\u8a00\u7684\u5168\u90e8\u7075\u6d3b\u6027\u3002<\/p>\n<ul>\n<li>\u4f60\u53ef\u4ee5\u4f7f\u7528<strong><code>if<\/code> \u8bed\u53e5<\/strong>\u6765\u51b3\u5b9a\u662f\u5426\u663e\u793a\u67d0\u4e2a\u5143\u7d20\u3002<\/li>\n<li>\u4f60\u53ef\u4ee5\u4f7f\u7528<strong><code>for<\/code> \u5faa\u73af<\/strong>\u6765\u52a8\u6001\u751f\u6210\u5217\u8868\u3002<\/li>\n<li>\u4f60\u53ef\u4ee5\u5b9a\u4e49\u53d8\u91cf\u3001\u8c03\u7528\u8f85\u52a9\u51fd\u6570\u7b49\u3002<br \/>\n\u8fd9\u79cd\u7075\u6d3b\u6027\u662fCompose\u7684\u5f3a\u5927\u4f18\u52bf\u4e4b\u4e00\uff0c\u8ba9\u4f60\u53ef\u4ee5\u66f4\u7b80\u6d01\u3001\u81ea\u7136\u5730\u6784\u5efa\u52a8\u6001\u754c\u9762\u3002<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"%E2%9A%99%EF%B8%8F_%E6%A0%B8%E5%BF%83%E6%9C%BA%E5%88%B6%EF%BC%9A%E6%99%BA%E8%83%BD%E9%87%8D%E7%BB%84\"><\/span>\u2699\ufe0f \u6838\u5fc3\u673a\u5236\uff1a\u667a\u80fd\u91cd\u7ec4<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u91cd\u7ec4\u662fCompose\u54cd\u5e94\u72b6\u6001\u53d8\u5316\u3001\u66f4\u65b0\u754c\u9762\u7684\u6838\u5fc3\u673a\u5236\u3002\u4e3a\u4e86\u63d0\u9ad8\u6548\u7387\uff0cCompose\u91c7\u7528\u4e86\u4e00\u7cfb\u5217\u4f18\u5316\u7b56\u7565\uff0c\u7406\u89e3\u8fd9\u4e9b\u5bf9\u4f60\u5199\u51fa\u6b63\u786e\u3001\u9ad8\u6548\u7684\u4ee3\u7801\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<ul>\n<li><strong>\u8df3\u8fc7\u4e0d\u5fc5\u8981\u7684\u91cd\u7ec4<\/strong>\uff1aCompose\u4f1a\u5c3d\u529b\u53ea\u91cd\u7ec4\u90a3\u4e9b\u8f93\u5165\u53c2\u6570\u5df2\u66f4\u6539\u7684\u90e8\u5206\u3002\u4f8b\u5982\uff0c\u5728\u5217\u8868\u4e2d\uff0c\u5982\u679c<code>header<\/code>\u53d8\u4e86\u800c<code>names<\/code>\u6ca1\u53d8\uff0c<code>LazyColumn<\/code>\u7684\u5217\u8868\u9879\u5c31\u53ef\u80fd\u88ab\u8df3\u8fc7\uff0c\u4e0d\u4f1a\u91cd\u7ec4\u3002<\/li>\n<li><strong>\u4e50\u89c2\u5730\u53d6\u6d88\u548c\u91cd\u542f<\/strong>\uff1a\u91cd\u7ec4\u662f\u4e50\u89c2\u64cd\u4f5c\uff0c\u5982\u679c\u5728\u65b0\u91cd\u7ec4\u5b8c\u6210\u524d\u53c2\u6570\u53c8\u53d8\u4e86\uff0cCompose\u4f1a\u53d6\u6d88\u5f53\u524d\u91cd\u7ec4\u5e76\u7528\u65b0\u53c2\u6570\u91cd\u65b0\u5f00\u59cb\u3002<\/li>\n<li><strong>\u9ad8\u9891\u6267\u884c<\/strong>\uff1a\u53ef\u7ec4\u5408\u51fd\u6570\u53ef\u80fd\u975e\u5e38\u9891\u7e41\u5730\u8fd0\u884c\uff08\u4f8b\u5982\u52a8\u753b\u7684\u6bcf\u4e00\u5e27\uff09\u3002\u56e0\u6b64\uff0c\u51fd\u6570\u5185\u90e8\u7edd\u4e0d\u80fd\u6267\u884c\u8017\u65f6\u64cd\u4f5c\uff08\u5982\u8bfb\u53d6\u6587\u4ef6\uff09\uff0c\u5426\u5219\u4f1a\u5bfc\u81f4\u754c\u9762\u5361\u987f\u3002<\/li>\n<li><strong>\u53ef\u80fd\u5e76\u884c\u8fd0\u884c<\/strong>\uff1a\u4e3a\u4e86\u4f18\u5316\u6027\u80fd\uff0cCompose\u53ef\u4ee5\u5728\u540e\u53f0\u7ebf\u7a0b\u6c60\u4e2d<strong>\u5e76\u884c\u6267\u884c<\/strong>\u4e0d\u540c\u7684\u53ef\u7ec4\u5408\u51fd\u6570\u3002<\/li>\n<li><strong>\u6267\u884c\u987a\u5e8f\u4e0d\u786e\u5b9a<\/strong>\uff1a\u540c\u4e00\u5c42\u7ea7\u4e0b\u7684\u53ef\u7ec4\u5408\u51fd\u6570\u8c03\u7528\uff08\u5982<code>StartScreen()<\/code>\u548c<code>EndScreen()<\/code>\uff09\uff0c\u5176<strong>\u6267\u884c\u987a\u5e8f\u662f\u4e0d\u4fdd\u8bc1\u7684<\/strong>\u3002\u5b83\u4eec\u4e0d\u5e94\u76f8\u4e92\u4f9d\u8d56\u3002<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"%E2%9A%A0%EF%B8%8F_%E6%9C%80%E9%87%8D%E8%A6%81%E7%9A%84%E8%A7%84%E5%88%99%EF%BC%9A%E6%97%A0%E5%89%AF%E4%BD%9C%E7%94%A8\"><\/span>\u26a0\ufe0f \u6700\u91cd\u8981\u7684\u89c4\u5219\uff1a\u65e0\u526f\u4f5c\u7528<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u4e0a\u8ff0\u6240\u6709\u4f18\u5316\u7b56\u7565\uff08\u8df3\u8fc7\u3001\u53d6\u6d88\u3001\u5e76\u884c\u3001\u987a\u5e8f\u4e0d\u5b9a\uff09\u5171\u540c\u6307\u5411\u4e86Compose\u7f16\u7a0b\u4e2d<strong>\u6700\u91cd\u8981\u7684\u4e00\u6761\u89c4\u5219\uff1a\u53ef\u7ec4\u5408\u51fd\u6570\u5fc5\u987b\u4fdd\u6301\u201c\u65e0\u526f\u4f5c\u7528\u201d<\/strong>\u3002<\/p>\n<p>\u6240\u8c13<strong>\u526f\u4f5c\u7528<\/strong>\uff0c\u662f\u6307\u5bf9\u53ef\u7ec4\u5408\u51fd\u6570\u4f5c\u7528\u57df\u5916\u90e8\u7684\u53ef\u89c1\u72b6\u6001\u6240\u505a\u7684\u4efb\u4f55\u66f4\u6539\u3002\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u5199\u5165\u5171\u4eab\u5bf9\u8c61\u7684\u5c5e\u6027\u6216\u5168\u5c40\u53d8\u91cf\u3002<\/li>\n<li>\u66f4\u65b0<code>ViewModel<\/code>\u4e2d\u7684\u53ef\u89c2\u5bdf\u9879\u3002<\/li>\n<li>\u5199\u5165<code>SharedPreferences<\/code>\u6216\u6570\u636e\u5e93\u3002<\/li>\n<\/ul>\n<p>\u8fdd\u53cd\u8fd9\u6761\u89c4\u5219\u4f1a\u5bfc\u81f4\u96be\u4ee5\u9884\u6d4b\u7684bug\uff0c\u6bd4\u5982\u754c\u9762\u663e\u793a\u9519\u8bef\u7684\u72b6\u6001\uff0c\u6216\u662f\u5728\u91cd\u7ec4\u88ab\u53d6\u6d88\u540e\u4f9d\u7136\u9519\u8bef\u5730\u5e94\u7528\u4e86\u67d0\u4e9b\u64cd\u4f5c\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E2%9C%85_%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5%E4%B8%8E%E6%A8%A1%E5%BC%8F\"><\/span>\u2705 \u6700\u4f73\u5b9e\u8df5\u4e0e\u6a21\u5f0f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u4e3a\u4e86\u9075\u5faa\u4e0a\u8ff0\u89c4\u5219\uff0c\u4f60\u9700\u8981\u91c7\u7528\u65b0\u7684\u7f16\u7a0b\u6a21\u5f0f\uff1a<\/p>\n<ul>\n<li>\n<p><strong>\u5c06\u6570\u636e\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165<\/strong>\uff1a\u4e0d\u8981\u4ece\u53ef\u7ec4\u5408\u51fd\u6570\u5185\u90e8\u8bfb\u53d6<code>SharedPreferences<\/code>\u6216\u8d44\u6e90\uff0c\u800c\u662f\u5c06\u8bfb\u53d6\u540e\u7684\u503c\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u8fdb\u6765\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u901a\u8fc7\u56de\u8c03\u89e6\u53d1\u64cd\u4f5c<\/strong>\uff1a\u5f53\u7528\u6237\u4ea4\u4e92\u9700\u8981\u6539\u53d8\u72b6\u6001\u65f6\uff08\u5982\u70b9\u51fb\u6309\u94ae\uff09\uff0c\u901a\u8fc7\u56de\u8c03\u51fd\u6570\uff08\u5982<code>onClick<\/code>\uff09\u5c06\u4e8b\u4ef6\u4f20\u9012\u7ed9<code>ViewModel<\/code>\u6216\u5176\u4ed6\u903b\u8f91\u5c42\u53bb\u5904\u7406\u72b6\u6001\u66f4\u65b0\u3002<\/p>\n<p>kotlin<\/p>\n<pre><code>\/\/ \u6b63\u786e\u505a\u6cd5\uff1a\u65e0\u526f\u4f5c\u7528\uff0c\u4ec5\u4f9d\u8d56\u8f93\u5165\u548c\u56de\u8c03\n@Composable\nfun SharedPrefsToggle(\n  value: Boolean, \/\/ \u72b6\u6001\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165\n  onValueChanged: (Boolean) -> Unit \/\/ \u64cd\u4f5c\u901a\u8fc7\u56de\u8c03\u4f20\u51fa\n) {\n  Checkbox(checked = value, onCheckedChange = onValueChanged)\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"%F0%9F%93%8C_%E6%80%BB%E7%BB%93%E8%A6%81%E7%82%B9\"><\/span>\ud83d\udccc \u603b\u7ed3\u8981\u70b9<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u6838\u5fc3\u6982\u5ff5<\/th>\n<th style=\"text-align: left;\">\u7b80\u8981\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><strong>\u58f0\u660e\u6027UI<\/strong><\/td>\n<td style=\"text-align: left;\">UI\u662f\u72b6\u6001\u7684\u51fd\u6570\uff0cUI = f(\u72b6\u6001)\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>\u53ef\u7ec4\u5408\u51fd\u6570<\/strong><\/td>\n<td style=\"text-align: left;\">\u7528<code>@Composable<\/code>\u6807\u8bb0\uff0c\u63cf\u8ff0UI\uff0c\u65e0\u8fd4\u56de\u503c\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>\u667a\u80fd\u91cd\u7ec4<\/strong><\/td>\n<td style=\"text-align: left;\">\u72b6\u6001\u53d8\u5316\u65f6\uff0c\u9ad8\u6548\u3001\u667a\u80fd\u5730\u66f4\u65b0UI\u7684\u673a\u5236\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>\u65e0\u526f\u4f5c\u7528<\/strong><\/td>\n<td style=\"text-align: left;\"><strong>\u6700\u91cd\u8981\u7684\u89c4\u5219<\/strong>\uff1a\u4e0d\u4fee\u6539\u5916\u90e8\u72b6\u6001\uff0c\u4e0d\u6267\u884c\u8017\u65f6\u64cd\u4f5c\u3002<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><strong>\u72b6\u6001\u63d0\u5347<\/strong><\/td>\n<td style=\"text-align: left;\">\u5c06\u72b6\u6001\u79fb\u81f3\u53ef\u7ec4\u5408\u9879\u5916\u90e8\uff0c\u901a\u8fc7\u53c2\u6570\u548c\u56de\u8c03\u4f20\u9012\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1><span class=\"ez-toc-section\" id=\"%E4%BA%8C%E3%80%81Compose%E6%B3%A8%E8%A7%A3\"><\/span>\u4e8c\u3001@Compose\u6ce8\u89e3<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h3><span class=\"ez-toc-section\" id=\"%E4%B8%80%E5%8F%A5%E8%AF%9D%E7%90%86%E8%A7%A3\"><\/span><strong>\u4e00\u53e5\u8bdd\u7406\u89e3<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><code>@Composable<\/code> \u5c31\u662f\u544a\u8bc9 Compose\uff1a&quot;<strong>\u8fd9\u4e2a\u51fd\u6570\u9700\u8981\u88ab\u8ffd\u8e2a\uff0c\u5f53\u5b83\u4f9d\u8d56\u7684\u6570\u636e\u53d8\u5316\u65f6\uff0c\u91cd\u65b0\u6267\u884c\u5b83<\/strong>&quot;\u3002<\/p>\n<h3><span class=\"ez-toc-section\" id=\"3%E4%B8%AA%E6%A0%B8%E5%BF%83%E7%82%B9\"><\/span><strong>3\u4e2a\u6838\u5fc3\u70b9<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"1_%E5%AE%83%E4%B8%8D%E6%98%AF%E6%99%AE%E9%80%9A%E5%87%BD%E6%95%B0\"><\/span><strong>1. \u5b83\u4e0d\u662f\u666e\u901a\u51fd\u6570<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>kotlin<\/p>\n<pre><code>\/\/ \u666e\u901a\u51fd\u6570\uff1a\u6267\u884c\u4e00\u6b21\u5c31\u5b8c\u4e8b\nfun sayHello() = println(&quot;Hello&quot;)\n\n\/\/ Composable\uff1a\u53ef\u4ee5\u88ab\u53cd\u590d\u6267\u884c\uff08\u91cd\u7ec4\uff09\n@Composable\nfun SayHello() {\n    println(&quot;Hello&quot;)  \/\/ \u5f53\u4f9d\u8d56\u7684\u72b6\u6001\u53d8\u5316\u65f6\uff0c\u4f1a\u518d\u6b21\u6267\u884c\n}<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"2_%E5%AE%83%E5%BF%85%E9%A1%BB%E8%A2%AB_Composable_%E5%87%BD%E6%95%B0%E8%B0%83%E7%94%A8\"><\/span><strong>2. \u5b83\u5fc5\u987b\u88ab @Composable \u51fd\u6570\u8c03\u7528<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>kotlin<\/p>\n<pre><code>\/\/ \u274c \u9519\u8bef\nfun normalFunction() {\n    SayHello()  \/\/ \u7f16\u8bd1\u9519\u8bef\uff01\n}\n\n\/\/ \u2705 \u6b63\u786e\n@Composable\nfun composableFunction() {\n    SayHello()  \/\/ \u53ef\u4ee5\u8c03\u7528\n}<\/code><\/pre>\n<h4><span class=\"ez-toc-section\" id=\"3_%E5%AE%83%E5%8F%AF%E4%BB%A5%E8%87%AA%E5%8A%A8%E5%93%8D%E5%BA%94%E6%95%B0%E6%8D%AE%E5%8F%98%E5%8C%96\"><\/span><strong>3. \u5b83\u53ef\u4ee5\u81ea\u52a8\u54cd\u5e94\u6570\u636e\u53d8\u5316<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>kotlin<\/p>\n<pre><code>@Composable\nfun Counter() {\n    var count by remember { mutableStateOf(0) }\n\n    \/\/ \u5f53 count \u53d8\u5316\u65f6\uff0c\u8fd9\u4e2a Text \u4f1a\u81ea\u52a8\u66f4\u65b0\n    Text(&quot;\u8ba1\u6570: $count&quot;)  \n\n    Button(onClick = { count++ }) {\n        Text(&quot;\u589e\u52a0&quot;)\n    }\n}<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"%E8%AE%B0%E5%BF%86%E5%8F%A3%E8%AF%80\"><\/span><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<blockquote>\n<p><strong>&quot;@Composable \u662f\u54cd\u5e94\u5f0f\u7684\u6807\u8bb0\uff0c\u8ba9\u51fd\u6570\u53ef\u4ee5\u53cd\u590d\u6267\u884c\u5e76\u81ea\u52a8\u66f4\u65b0&quot;<\/strong><\/p>\n<\/blockquote>\n<h3><span class=\"ez-toc-section\" id=\"%E5%AF%B9%E6%AF%94%E7%90%86%E8%A7%A3\"><\/span><strong>\u5bf9\u6bd4\u7406\u89e3<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u666e\u901a\u51fd\u6570<\/th>\n<th style=\"text-align: left;\">@Composable \u51fd\u6570<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\u6267\u884c\u4e00\u6b21<\/td>\n<td style=\"text-align: left;\">\u53ef\u4ee5\u6267\u884c\u591a\u6b21\uff08\u91cd\u7ec4\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u4e0d\u8ffd\u8e2a\u6570\u636e<\/td>\n<td style=\"text-align: left;\">\u8ffd\u8e2a\u6570\u636e\u53d8\u5316<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u54ea\u91cc\u90fd\u80fd\u8c03<\/td>\n<td style=\"text-align: left;\">\u53ea\u80fd\u5728 @Composable \u4e2d\u8c03<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u81ea\u5df1\u63a7\u5236\u66f4\u65b0<\/td>\n<td style=\"text-align: left;\">Compose \u81ea\u52a8\u63a7\u5236\u66f4\u65b0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><span class=\"ez-toc-section\" id=\"90_%E7%9A%84%E5%9C%BA%E6%99%AF%E4%BD%A0%E5%8F%AA%E9%9C%80%E8%A6%81%E7%9F%A5%E9%81%93%EF%BC%9A\"><\/span><strong>90% \u7684\u573a\u666f\u4f60\u53ea\u9700\u8981\u77e5\u9053\uff1a<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>\u7528 <code>@Composable<\/code> \u6807\u8bb0\u4f60\u7684 UI \u51fd\u6570<\/li>\n<li>\u5728\u91cc\u9762\u53ef\u4ee5\u4f7f\u7528 <code>remember<\/code>\u3001<code>mutableStateOf<\/code><\/li>\n<li>\u6570\u636e\u53d8\u4e86 UI \u81ea\u52a8\u66f4\u65b0<\/li>\n<\/ul>\n<button class=\"simplefavorite-button\" data-postid=\"16202\" 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>https:\/\/developer.android.google.cn\/develop\/ui\/com [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1252],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/16202"}],"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=16202"}],"version-history":[{"count":4,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/16202\/revisions"}],"predecessor-version":[{"id":16290,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/16202\/revisions\/16290"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16202"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}