{"id":107713,"date":"2026-09-20T05:58:19","date_gmt":"2026-09-19T21:58:19","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/107713.html"},"modified":"2026-09-20T05:58:19","modified_gmt":"2026-09-19T21:58:19","slug":"%e3%80%90jetpack-compose%e5%9f%ba%e7%a1%80%e8%af%ad%e6%b3%95%e5%ad%a6%e4%b8%8e%e7%bb%83%e3%80%91%e7%ac%ac2%e8%af%be-state%e7%8a%b6%e6%80%81-%e7%82%b9%e5%87%bb%e4%ba%a4%e4%ba%92","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/107713.html","title":{"rendered":"\u3010Jetpack Compose\u57fa\u7840\u8bed\u6cd5\u5b66\u4e0e\u7ec3\u3011\u7b2c2\u8bfe State\u72b6\u6001 + \u70b9\u51fb\u4ea4\u4e92"},"content":{"rendered":"<h2>\u524d\u8a00<\/h2>\n<p>\u4e0a\u4e00\u8282\u8bfe\u6211\u4eec\u5b8c\u6210\u6700\u7b80HelloWorld&#xff0c;\u8ba4\u8bc6\u4e86 &#064;Composable \u53ef\u7ec4\u5408\u51fd\u6570\u3001\u9884\u89c8\u6ce8\u89e3\u3002<br \/>\nCompose\u58f0\u660e\u5f0fUI\u7684\u6838\u5fc3&#xff1a;\u754c\u9762\u8ddf\u968f\u72b6\u6001\u81ea\u52a8\u66f4\u65b0\u3002<br \/>\n\u672c\u8bfe\u91cd\u70b9\u5b66\u4e60\u72b6\u6001\u5b9a\u4e49\u3001\u8bb0\u5fc6\u72b6\u6001\u3001\u6309\u94ae\u70b9\u51fb\u4e8b\u4ef6&#xff0c;\u6253\u901a\u300c\u72b6\u6001\u2011\u91cd\u7ec4\u2011\u754c\u9762\u5237\u65b0\u300d\u5b8c\u6574\u95ed\u73af\u3002<\/p>\n<p>\u524d\u7f6e&#xff1a;\u5b8c\u6210\u7b2c1\u8bfe&#xff0c;Compose\u57fa\u7840\u9879\u76ee\u6b63\u5e38\u53ef\u7f16\u8bd1\u9884\u89c8<\/p>\n<h2>\u4e00\u3001\u5b8c\u6574\u53ef\u8fd0\u884c\u793a\u4f8b\u6e90\u7801<\/h2>\n<p><span class=\"token keyword\">package<\/span> com<span class=\"token punctuation\">.<\/span>example<span class=\"token punctuation\">.<\/span>composefirst<\/p>\n<p><span class=\"token keyword\">import<\/span> android<span class=\"token punctuation\">.<\/span>os<span class=\"token punctuation\">.<\/span>Bundle<br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>activity<span class=\"token punctuation\">.<\/span>ComponentActivity<br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>activity<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>setContent<br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>material3<span class=\"token punctuation\">.<\/span>Button<br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>material3<span class=\"token punctuation\">.<\/span>Text<br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>runtime<span class=\"token punctuation\">.<\/span>Composable<br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>runtime<span class=\"token punctuation\">.<\/span>getValue<br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>runtime<span class=\"token punctuation\">.<\/span>mutableIntStateOf<br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>runtime<span class=\"token punctuation\">.<\/span>remember<br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>runtime<span class=\"token punctuation\">.<\/span>setValue<br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>ui<span class=\"token punctuation\">.<\/span>tooling<span class=\"token punctuation\">.<\/span>preview<span class=\"token punctuation\">.<\/span>Preview<\/p>\n<p><span class=\"token keyword\">class<\/span> MainActivity <span class=\"token operator\">:<\/span> <span class=\"token function\">ComponentActivity<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">override<\/span> <span class=\"token keyword\">fun<\/span> <span class=\"token function\">onCreate<\/span><span class=\"token punctuation\">(<\/span>savedInstanceState<span class=\"token operator\">:<\/span> Bundle<span class=\"token operator\">?<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">super<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">onCreate<\/span><span class=\"token punctuation\">(<\/span>savedInstanceState<span class=\"token punctuation\">)<\/span><br \/>\n        setContent <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token function\">CounterPage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token annotation builtin\">&#064;Composable<\/span><br \/>\n<span class=\"token keyword\">fun<\/span> <span class=\"token function\">CounterPage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5b9a\u4e49\u8bb0\u5fc6\u578b\u72b6\u6001<\/span><br \/>\n    <span class=\"token keyword\">var<\/span> count <span class=\"token keyword\">by<\/span> remember <span class=\"token punctuation\">{<\/span> <span class=\"token function\">mutableIntStateOf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token function\">Text<\/span><span class=\"token punctuation\">(<\/span>text <span class=\"token operator\">&#061;<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;\u5f53\u524d\u8ba1\u6570&#xff1a;<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">$<\/span><span class=\"token expression\">count<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token function\">Button<\/span><span class=\"token punctuation\">(<\/span>onClick <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        count <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">Text<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;\u70b9\u6211&#043;1&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token annotation builtin\">&#064;Preview<\/span><br \/>\n<span class=\"token annotation builtin\">&#064;Composable<\/span><br \/>\n<span class=\"token keyword\">fun<\/span> <span class=\"token function\">CounterPreview<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">CounterPage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h2>\u4e8c\u3001\u9010\u884c\u4ee3\u7801\u89e3\u8bfb<\/h2>\n<h3>1.  remember { \u2026 }<\/h3>\n<p>remember  \u662f\u72b6\u6001\u8bb0\u5fc6\u51fd\u6570\u3002<br \/>\n\u53ef\u7ec4\u5408\u51fd\u6570\u6bcf\u6b21\u91cd\u7ec4\u90fd\u4f1a\u5b8c\u6574\u6267\u884c\u4e00\u904d&#xff0c;\u5982\u679c\u4e0d\u5957\u4e0a remember &#xff0c;\u53d8\u91cf\u6bcf\u6b21\u90fd\u4f1a\u91cd\u7f6e&#xff0c;\u65e0\u6cd5\u4fdd\u5b58\u4e0a\u4e00\u6b21\u6570\u503c\u3002<br \/>\n\u4f5c\u7528&#xff1a;\u5728\u91cd\u7ec4\u8fc7\u7a0b\u4e2d\u4fdd\u5b58\u6570\u636e&#xff0c;\u4e0d\u4f1a\u88ab\u53cd\u590d\u521d\u59cb\u5316\u3002<\/p>\n<h3>2.  mutableIntStateOf(0)<\/h3>\n<p>\u751f\u6210\u53ef\u89c2\u5bdf\u7684\u6574\u578b\u72b6\u6001\u5bf9\u8c61&#xff0c;\u521d\u59cb\u503c0\u3002<br \/>\n\u914d\u5957\u8fd8\u6709&#xff1a; mutableStateOf \u901a\u7528\u4efb\u610f\u7c7b\u578b\u3001 mutableStringStateOf \u5b57\u7b26\u4e32\u4e13\u7528\u72b6\u6001\u3002<\/p>\n<h3>3.  var count by<\/h3>\n<p>by \u662f Kotlin \u5c5e\u6027\u59d4\u6258\u8bed\u6cd5\u3002<\/p>\n<ul>\n<li>\u4e0d\u52a0 by &#xff1a;\u4f60\u62ff\u5230\u7684\u662f\u72b6\u6001\u5bf9\u8c61  MutableIntState &#xff0c;\u53d6\u503c\u8981\u5199  .intValue &#xff1b;<\/li>\n<li>\u4f7f\u7528 by \u59d4\u6258&#xff1a;\u76f4\u63a5\u8bfb\u5199\u666e\u901a\u53d8\u91cf  count &#xff0c;\u8bed\u6cd5\u7b80\u6d01\u3002<\/li>\n<\/ul>\n<p>\u5bfc\u5165\u63d0\u793a<\/p>\n<p><span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>runtime<span class=\"token punctuation\">.<\/span>getValue<br \/>\n<span class=\"token keyword\">import<\/span> androidx<span class=\"token punctuation\">.<\/span>compose<span class=\"token punctuation\">.<\/span>runtime<span class=\"token punctuation\">.<\/span>setValue<\/p>\n<p>\u7f3a\u5c11\u8fd9\u4e24\u884c\u5bfc\u5165&#xff0c; by \u8bed\u6cd5\u4f1a\u76f4\u63a5\u62a5\u9519\u3002<\/p>\n<h3>4.  Button(onClick &#061; {})<\/h3>\n<p>\u6309\u94ae\u70b9\u51fb\u56de\u8c03&#xff0c; onClick \u662f\u65e0\u53c2Lambda\u3002<br \/>\n\u70b9\u51fb\u65f6\u4fee\u6539\u72b6\u6001\u53d8\u91cf  count &#043;&#061;1 \u3002<\/p>\n<h3>5. \u91cd\u7ec4\u89e6\u53d1\u903b\u8f91<\/h3>\n<p>count \u5c5e\u4e8e\u88abCompose\u76d1\u542c\u7684\u72b6\u6001\u3002\u4e00\u65e6\u6570\u503c\u53d1\u751f\u53d8\u66f4&#xff0c;Compose\u89e6\u53d1\u91cd\u7ec4&#xff0c;\u91cd\u65b0\u8fd0\u884c CounterPage &#xff0c;\u754c\u9762\u4e0aText\u81ea\u52a8\u5237\u65b0\u51fa\u65b0\u6570\u5b57\u3002<\/p>\n<h3>\u5173\u952e\u70b9&#xff1a;<\/h3>\n<p>\u6211\u4eec\u6ca1\u6709\u624b\u52a8\u5199\u5237\u65b0\u754c\u9762\u4ee3\u7801&#xff0c;\u72b6\u6001\u53d8\u66f4\u81ea\u52a8\u9a71\u52a8\u754c\u9762\u66f4\u65b0\u3002<\/p>\n<h2>\u4e09\u3001\u6838\u5fc3\u6982\u5ff5\u533a\u5206<\/h2>\n<li>\u666e\u901a\u5c40\u90e8\u53d8\u91cf<\/li>\n<p><span class=\"token keyword\">var<\/span> count <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><\/p>\n<p>\u6bcf\u6b21\u91cd\u7ec4\u91cd\u7f6e&#xff0c;\u70b9\u51fb\u6309\u94ae\u754c\u9762\u4e0d\u4f1a\u53d8\u5316&#xff0c;\u65e0\u6cd5\u7528\u4e8eUI\u72b6\u6001\u3002<\/p>\n<li>remember &#043; \u72b6\u6001\u5bf9\u8c61<\/li>\n<p><span class=\"token keyword\">var<\/span> count <span class=\"token keyword\">by<\/span> remember <span class=\"token punctuation\">{<\/span> <span class=\"token function\">mutableIntStateOf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">}<\/span><\/p>\n<p>remember\u7559\u5b58\u53d8\u91cf&#xff1b;\u72b6\u6001\u5bf9\u8c61\u53ef\u88ab\u6846\u67b6\u76d1\u542c&#xff1b;\u4fee\u6539\u72b6\u6001\u89e6\u53d1\u91cd\u7ec4&#xff0c;\u754c\u9762\u5237\u65b0\u3002<\/p>\n<h3>\u6613\u9519\u70b9&#xff1a;<\/h3>\n<p>remember \u53ea\u80fd\u653e\u5728 &#064;Composable \u51fd\u6570\u5185\u90e8&#xff0c;\u4e0d\u80fd\u653e\u5728\u666e\u901a\u51fd\u6570\u3001\u5168\u5c40\u4f5c\u7528\u57df\u3002<\/p>\n<h2>\u56db\u3001\u7efc\u5408\u7ec3\u4e60\u9898<\/h2>\n<h3>\u586b\u7a7a\u9898<\/h3>\n<li>\u7528\u6765\u5728\u91cd\u7ec4\u671f\u95f4\u4fdd\u5b58\u6570\u636e\u7684\u51fd\u6570\u662f________\u3002<\/li>\n<li>\u521b\u5efa\u6574\u578b\u53ef\u76d1\u542c\u72b6\u6001\u7684\u51fd\u6570\u662f________\u3002<\/li>\n<li>Kotlin ________\u8bed\u6cd5&#xff0c;\u53ef\u4ee5\u7701\u53bb .intValue &#xff0c;\u76f4\u63a5\u8bfb\u5199\u72b6\u6001\u503c\u3002<\/li>\n<p>\u7b54\u6848\u4e0e\u89e3\u6790<\/p>\n<li>remember &#xff1b;\u89e3\u6790&#xff1a;\u6ca1\u6709remember&#xff0c;\u6bcf\u6b21\u91cd\u7ec4\u53d8\u91cf\u91cd\u7f6e&#xff0c;\u72b6\u6001\u4e22\u5931\u3002<\/li>\n<li>mutableIntStateOf &#xff1b;\u89e3\u6790&#xff1a;\u4e13\u95e8\u7528\u4e8e\u6574\u6570\u72b6\u6001&#xff0c;\u66ff\u4ee3\u65e7\u7248 mutableStateOf(0) &#xff0c;\u6027\u80fd\u66f4\u597d\u3002<\/li>\n<li>\u5c5e\u6027\u59d4\u6258&#xff08;by&#xff09;&#xff1b;\u89e3\u6790&#xff1a;by \u5c06\u53d6\u503c\u8d4b\u503c\u4ea4\u7ed9\u72b6\u6001\u4ee3\u7406&#xff0c;\u7b80\u5316\u4ee3\u7801\u3002<\/li>\n<h3>\u5224\u65ad\u9898<\/h3>\n<li>\u53bb\u6389 remember&#xff0c;\u70b9\u51fb\u6309\u94ae&#xff0c;\u6570\u503c\u4f1a\u81ea\u589e\u4f46\u662f\u754c\u9762\u4e0d\u4f1a\u66f4\u65b0\u3002&#xff08;&#xff09;<\/li>\n<p>\u7b54\u6848&#xff1a;\u9519\u8bef\u3002\u7406\u7531&#xff1a;\u6ca1\u6709remember&#xff0c;\u6bcf\u6b21\u91cd\u7ec4count\u91cd\u7f6e\u4e3a0&#xff0c;\u6570\u503c\u4e0d\u4f1a\u7d2f\u52a0&#xff0c;\u754c\u9762\u4e0d\u4f1a\u6709\u53d8\u5316\u3002<\/p>\n<li>onClick \u56de\u8c03\u5185\u90e8\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539 remember \u5305\u88f9\u7684\u72b6\u6001\u53d8\u91cf\u3002&#xff08;&#xff09;<\/li>\n<p>\u7b54\u6848&#xff1a;\u6b63\u786e\u3002\u7406\u7531&#xff1a;\u4fee\u6539\u53ef\u76d1\u542c\u72b6\u6001&#xff0c;\u4f1a\u89e6\u53d1\u91cd\u7ec4&#xff0c;\u81ea\u52a8\u5237\u65b0UI\u3002<\/p>\n<li>remember \u53ef\u4ee5\u76f4\u63a5\u5199\u5728\u9876\u5c42\u5168\u5c40\u4f4d\u7f6e\u3002&#xff08;&#xff09;<\/li>\n<p>\u7b54\u6848&#xff1a;\u9519\u8bef\u3002\u7406\u7531&#xff1a;remember \u5fc5\u987b\u8fd0\u884c\u5728\u53ef\u7ec4\u5408\u51fd\u6570\u7684Compose\u4e0a\u4e0b\u6587&#xff0c;\u5168\u5c40\u65e0\u6cd5\u8c03\u7528\u3002<\/p>\n<h3>\u7b80\u7b54\u9898<\/h3>\n<li>\u7b80\u8ff0\u666e\u901a\u53d8\u91cf\u548c remember&#043;\u72b6\u6001\u53d8\u91cf\u6700\u5927\u533a\u522b&#xff1f;<\/li>\n<p>\u53c2\u8003\u7b54\u6848&#xff1a;\u666e\u901a\u53d8\u91cf\u91cd\u7ec4\u65f6\u91cd\u65b0\u521d\u59cb\u5316&#xff0c;\u6570\u636e\u65e0\u6cd5\u7559\u5b58&#xff0c;\u6539\u52a8\u4e0d\u4f1a\u901a\u77e5\u754c\u9762&#xff1b;remember \u4fdd\u5b58\u53d8\u91cf&#xff0c;\u72b6\u6001\u5bf9\u8c61\u88ab\u6846\u67b6\u76d1\u542c&#xff0c;\u4fee\u6539\u540e\u81ea\u52a8\u91cd\u7ec4\u5237\u65b0\u9875\u9762\u3002<\/p>\n<li>\u4ee3\u7801\u5b9e\u64cd\u9898<\/li>\n<p>\u4fee\u6539\u793a\u4f8b\u4ee3\u7801&#xff1a;\u589e\u52a0\u91cd\u7f6e\u6309\u94ae&#xff0c;\u70b9\u51fb\u540e count \u5f52\u96f6\u3002\u5199\u51fa\u5b8c\u6574 CounterPage \u51fd\u6570\u3002\u53c2\u8003\u7b54\u6848<\/p>\n<p><span class=\"token annotation builtin\">&#064;Composable<\/span><br \/>\n<span class=\"token keyword\">fun<\/span> <span class=\"token function\">CounterPage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">var<\/span> count <span class=\"token keyword\">by<\/span> remember <span class=\"token punctuation\">{<\/span> <span class=\"token function\">mutableIntStateOf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token function\">Text<\/span><span class=\"token punctuation\">(<\/span>text <span class=\"token operator\">&#061;<\/span> <span class=\"token string-literal singleline\"><span class=\"token string\">&#034;\u5f53\u524d\u8ba1\u6570&#xff1a;<\/span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">$<\/span><span class=\"token expression\">count<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token function\">Button<\/span><span class=\"token punctuation\">(<\/span>onClick <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        count <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">Text<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;\u70b9\u6211&#043;1&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token function\">Button<\/span><span class=\"token punctuation\">(<\/span>onClick <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        count <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">Text<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-literal singleline\"><span class=\"token string\">&#034;\u91cd\u7f6e&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u89e3\u6790&#xff1a;\u65b0\u589e\u7b2c\u4e8c\u4e2aButton&#xff0c;\u70b9\u51fb\u56de\u8c03\u628acount\u8d4b\u503c\u4e3a0&#xff0c;\u72b6\u6001\u53d8\u66f4\u89e6\u53d1\u754c\u9762\u5237\u65b0\u3002<\/p>\n<h2>\u4e94\u3001\u672c\u8bfe\u5c0f\u7ed3<\/h2>\n<li>remember &#xff1a;\u8de8\u91cd\u7ec4\u4fdd\u5b58\u6570\u636e&#xff1b;<\/li>\n<li>mutableXXStateOf &#xff1a;\u53ef\u88ab\u76d1\u542c\u7684\u72b6\u6001&#xff1b;<\/li>\n<li>by \u5c5e\u6027\u59d4\u6258\u7b80\u5316\u8bfb\u5199&#xff1b;<\/li>\n<li>\u6539\u53d8\u72b6\u6001 \u2192 \u81ea\u52a8\u91cd\u7ec4 \u2192 UI\u66f4\u65b0&#xff0c;\u4e0d\u9700\u8981\u624b\u52a8\u5237\u65b0\u63a7\u4ef6\u3002<\/li>\n<p>\u4e0b\u4e00\u8bfe&#xff1a;\u5e03\u5c40\u7ec4\u4ef6 Column\u3001Row\u3001Box&#xff0c;\u63a7\u5236\u5143\u7d20\u6392\u5217\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00<br \/>\n\u4e0a\u4e00\u8282\u8bfe\u6211\u4eec\u5b8c\u6210\u6700\u7b80HelloWorld&#xff0c;\u8ba4\u8bc6\u4e86 Composable \u53ef\u7ec4\u5408\u51fd\u6570\u3001\u9884\u89c8\u6ce8\u89e3\u3002<br \/>\nCompose\u58f0\u660e\u5f0fUI\u7684\u6838\u5fc3&#xff1a;\u754c\u9762\u8ddf\u968f\u72b6\u6001\u81ea\u52a8\u66f4\u65b0\u3002<br \/>\n\u672c\u8bfe\u91cd\u70b9\u5b66\u4e60\u72b6\u6001\u5b9a\u4e49\u3001\u8bb0\u5fc6\u72b6\u6001\u3001\u6309\u94ae\u70b9\u51fb\u4e8b\u4ef6&#xff0c;\u6253\u901a\u300c\u72b6\u6001\u2011\u91cd\u7ec4\u2011\u754c\u9762\u5237\u65b0\u300d\u5b8c\u6574\u95ed\u73af\u3002<br \/>\n\u524d\u7f6e&#xff1a;\u5b8c\u6210\u7b2c1\u8bfe&#xff0c;Compose\u57fa\u7840\u9879\u76ee\u6b63\u5e38\u53ef\u7f16\u8bd1\u9884\u89c8<br \/>\n\u4e00\u3001\u5b8c\u6574\u53ef\u8fd0\u884c\u793a\u4f8b\u6e90\u7801package com.example.composefirstimport andro<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[84,5754,1693,780,371],"topic":[],"class_list":["post-107713","post","type-post","status-publish","format-standard","hentry","category-server","tag-android","tag-android-jetpack","tag-kotlin","tag-ui","tag-371"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Jetpack Compose\u57fa\u7840\u8bed\u6cd5\u5b66\u4e0e\u7ec3\u3011\u7b2c2\u8bfe State\u72b6\u6001 + \u70b9\u51fb\u4ea4\u4e92 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/107713.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Jetpack Compose\u57fa\u7840\u8bed\u6cd5\u5b66\u4e0e\u7ec3\u3011\u7b2c2\u8bfe State\u72b6\u6001 + \u70b9\u51fb\u4ea4\u4e92 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u524d\u8a00 \u4e0a\u4e00\u8282\u8bfe\u6211\u4eec\u5b8c\u6210\u6700\u7b80HelloWorld&#xff0c;\u8ba4\u8bc6\u4e86 Composable \u53ef\u7ec4\u5408\u51fd\u6570\u3001\u9884\u89c8\u6ce8\u89e3\u3002 Compose\u58f0\u660e\u5f0fUI\u7684\u6838\u5fc3&#xff1a;\u754c\u9762\u8ddf\u968f\u72b6\u6001\u81ea\u52a8\u66f4\u65b0\u3002 \u672c\u8bfe\u91cd\u70b9\u5b66\u4e60\u72b6\u6001\u5b9a\u4e49\u3001\u8bb0\u5fc6\u72b6\u6001\u3001\u6309\u94ae\u70b9\u51fb\u4e8b\u4ef6&#xff0c;\u6253\u901a\u300c\u72b6\u6001\u2011\u91cd\u7ec4\u2011\u754c\u9762\u5237\u65b0\u300d\u5b8c\u6574\u95ed\u73af\u3002 \u524d\u7f6e&#xff1a;\u5b8c\u6210\u7b2c1\u8bfe&#xff0c;Compose\u57fa\u7840\u9879\u76ee\u6b63\u5e38\u53ef\u7f16\u8bd1\u9884\u89c8 \u4e00\u3001\u5b8c\u6574\u53ef\u8fd0\u884c\u793a\u4f8b\u6e90\u7801package com.example.composefirstimport andro\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/107713.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-19T21:58:19+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/107713.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/107713.html\",\"name\":\"\u3010Jetpack Compose\u57fa\u7840\u8bed\u6cd5\u5b66\u4e0e\u7ec3\u3011\u7b2c2\u8bfe State\u72b6\u6001 + \u70b9\u51fb\u4ea4\u4e92 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-19T21:58:19+00:00\",\"dateModified\":\"2026-09-19T21:58:19+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/107713.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/107713.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/107713.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Jetpack Compose\u57fa\u7840\u8bed\u6cd5\u5b66\u4e0e\u7ec3\u3011\u7b2c2\u8bfe State\u72b6\u6001 + \u70b9\u51fb\u4ea4\u4e92\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010Jetpack Compose\u57fa\u7840\u8bed\u6cd5\u5b66\u4e0e\u7ec3\u3011\u7b2c2\u8bfe State\u72b6\u6001 + \u70b9\u51fb\u4ea4\u4e92 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/107713.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Jetpack Compose\u57fa\u7840\u8bed\u6cd5\u5b66\u4e0e\u7ec3\u3011\u7b2c2\u8bfe State\u72b6\u6001 + \u70b9\u51fb\u4ea4\u4e92 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u524d\u8a00 \u4e0a\u4e00\u8282\u8bfe\u6211\u4eec\u5b8c\u6210\u6700\u7b80HelloWorld&#xff0c;\u8ba4\u8bc6\u4e86 Composable \u53ef\u7ec4\u5408\u51fd\u6570\u3001\u9884\u89c8\u6ce8\u89e3\u3002 Compose\u58f0\u660e\u5f0fUI\u7684\u6838\u5fc3&#xff1a;\u754c\u9762\u8ddf\u968f\u72b6\u6001\u81ea\u52a8\u66f4\u65b0\u3002 \u672c\u8bfe\u91cd\u70b9\u5b66\u4e60\u72b6\u6001\u5b9a\u4e49\u3001\u8bb0\u5fc6\u72b6\u6001\u3001\u6309\u94ae\u70b9\u51fb\u4e8b\u4ef6&#xff0c;\u6253\u901a\u300c\u72b6\u6001\u2011\u91cd\u7ec4\u2011\u754c\u9762\u5237\u65b0\u300d\u5b8c\u6574\u95ed\u73af\u3002 \u524d\u7f6e&#xff1a;\u5b8c\u6210\u7b2c1\u8bfe&#xff0c;Compose\u57fa\u7840\u9879\u76ee\u6b63\u5e38\u53ef\u7f16\u8bd1\u9884\u89c8 \u4e00\u3001\u5b8c\u6574\u53ef\u8fd0\u884c\u793a\u4f8b\u6e90\u7801package com.example.composefirstimport andro","og_url":"https:\/\/www.wsisp.com\/helps\/107713.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-19T21:58:19+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/107713.html","url":"https:\/\/www.wsisp.com\/helps\/107713.html","name":"\u3010Jetpack Compose\u57fa\u7840\u8bed\u6cd5\u5b66\u4e0e\u7ec3\u3011\u7b2c2\u8bfe State\u72b6\u6001 + \u70b9\u51fb\u4ea4\u4e92 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-19T21:58:19+00:00","dateModified":"2026-09-19T21:58:19+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/107713.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/107713.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/107713.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Jetpack Compose\u57fa\u7840\u8bed\u6cd5\u5b66\u4e0e\u7ec3\u3011\u7b2c2\u8bfe State\u72b6\u6001 + \u70b9\u51fb\u4ea4\u4e92"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/107713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=107713"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/107713\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=107713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=107713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=107713"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=107713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}