{"id":4735,"date":"2025-11-03T10:03:53","date_gmt":"2025-11-03T02:03:53","guid":{"rendered":"https:\/\/blog.odjbinail.cn\/?p=4735"},"modified":"2025-11-03T10:03:53","modified_gmt":"2025-11-03T02:03:53","slug":"harmonyos","status":"publish","type":"post","link":"https:\/\/blog.odjbinail.cn\/?p=4735","title":{"rendered":"HarmonyOS"},"content":{"rendered":"<h2>HarmonyOS \u4e09\u5927\u7279\u6027<\/h2>\n<ul>\n<li>\u786c\u4ef6\u4e92\u52a9\uff0c\u8d44\u6e90\u5171\u4eab<\/li>\n<li>\u4e00\u6b21\u5f00\u53d1\uff0c\u591a\u7aef\u90e8\u7f72<\/li>\n<li>\u7edf\u4e00 OS\uff0c\u5f39\u6027\u90e8\u7f72<\/li>\n<\/ul>\n<h3>\u786c\u4ef6\u4e92\u52a9\uff0c\u8d44\u6e90\u5171\u4eab<\/h3>\n<ul>\n<li>\u5206\u5e03\u5f0f\u8f6f\u603b\u7ebf<\/li>\n<li>\u5206\u5e03\u5f0f\u8bbe\u5907\u865a\u62df\u5316<\/li>\n<li>\u5206\u5e03\u5f0f\u6570\u636e\u7ba1\u7406<\/li>\n<li>\u5206\u5e03\u5f0f\u4efb\u52a1\u8c03\u5ea6<\/li>\n<li>\u5206\u5e03\u5f0f\u8fde\u63a5\u80fd\u529b<\/li>\n<\/ul>\n<h3>\u4e00\u6b21\u5f00\u53d1\uff0c\u591a\u7aef\u90e8\u7f72<\/h3>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/09\/2024102514580983.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/09\/2024102514580983.png\" alt=\"\" \/><\/p><\/noscript>\n<h3>\u7edf\u4e00 OS\uff0c\u5f39\u6027\u90e8\u7f72<\/h3>\n<ul>\n<li>\u7ec4\u4ef6\u53ef\u6709\u53ef\u65e0<\/li>\n<li>\u7ec4\u4ef6\u53ef\u5927\u53ef\u5c0f<\/li>\n<li>\u5e73\u53f0\u53ef\u5927\u53ef\u5c0f<\/li>\n<\/ul>\n<h2>\u5168\u89c6\u89d2\u4e86\u89e3 HarmonyOS \u67b6\u6784<\/h2>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/10\/2024102515012091.png\"  alt=\"\" \/><br \/>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/10\/2024102515012091.png\" alt=\"\" \/><br \/><\/noscript>\n<img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/10\/202410251549337.png\"  alt=\"\" \/><br \/>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/10\/202410251549337.png\" alt=\"\" \/><br \/><\/noscript>\n<img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/10\/2024102515500890.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/10\/2024102515500890.png\" alt=\"\" \/><\/p><\/noscript>\n<h2>\u521b\u5efa Hello World<\/h2>\n<p>bundle name : \u4f1a\u4f5c\u4e3a\u5e94\u7528\u4e0a\u4e0b\u7ebf\u7684\u552f\u4e00\u6807\u8bc6\u7b26\u3002\u9700\u8981\u4fdd\u969c\u552f\u4e00\u6027<br \/>\nsave location \uff1a\u8def\u5f84\u4e0d\u80fd\u5305\u542b\u4e2d\u6587\u5b57\u7b26<br \/>\nmodel : \u5e94\u7528\u6a21\u578b, \u4e3b\u63a8 Stage<\/p>\n<h2>TS \u5feb\u901f\u5165\u95e8<\/h2>\n<h3>\u7c7b\u578b\u63a8\u65ad<\/h3>\n<p>\u5982\u679c\u2f00\u4e2a\u53d8\u91cf\u6216\u5e38\u91cf\u7684\u58f0\u660e\u5305\u542b\u4e86\u521d\u59cb\u503c\uff0cTS \u4fbf\u53ef\u4ee5\u6839\u636e\u521d\u59cb\u503c\u8fdb\u2f8f\u7c7b\u578b\u63a8\u65ad\uff0c\u6b64\u65f6\u6211\u4eec\u5c31\u53ef\u4ee5<br \/>\n\u4e0d\u663e\u5f0f\u6307\u5b9a\u5176\u7c7b\u578b\uff0c\u4f8b\u5982:<\/p>\n<pre class=\"prettyprint linenums\" ><code>let c = 60;\nconsole.log(typeof c); \/\/number<\/code><\/pre>\n<h3>\u7c7b\u7684\u9759\u6001\u6210\u5458<\/h3>\n<p>Typescript \u4e2d\u7684\u7c7b\u4e2d\u53ef\u4ee5\u5305\u542b\u9759\u6001\u6210\u5458\uff08\u9759\u6001\u5c5e\u6027\u548c\u9759\u6001\u2f45\u6cd5\uff09\uff0c\u9759\u6001\u6210\u5458\u2faa\u5c5e\u4e8e\u7c7b\u672c\u8eab\uff0c\u2f7d\u4e0d<br \/>\n\u5c5e\u4e8e\u67d0\u4e2a\u5bf9\u8c61\u5b9e\u4f8b\u3002\u9759\u6001\u6210\u5458\u901a\u2f64\u2f64\u4e8e\u5b9a\u4e49\u2f00\u4e9b\u5e38\u91cf\uff0c\u6216\u8005\u2f2f\u5177\u2f45\u6cd5\u3002<\/p>\n<ul>\n<li>\u58f0\u660e\u9759\u6001\u6210\u5458<br \/>\n\u5b9a\u4e49\u9759\u6001\u6210\u5458\u9700\u8981\u4f7f\u2f64 static \u5173\u952e\u5b57\u3002<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>class Constants{\n static count:number=1;\n}\nclass Utils{\n static toLowerCase(str:string){\n return str.toLowerCase();\n }\n}\nconsole.log(Constants.count);\nconsole.log(Utils.toLowerCase(&#039;Hello World&#039;));<\/code><\/pre>\n<ul>\n<li>\u4f7f\u2f64\u9759\u6001\u6210\u5458<br \/>\n\u9759\u6001\u6210\u5458\u2f46\u9700\u901a\u8fc7\u5bf9\u8c61\u5b9e\u4f8b\u8bbf\u95ee\uff0c\u76f4\u63a5\u901a\u8fc7\u7c7b\u672c\u8eab\u8bbf\u95ee\u5373\u53ef\u3002<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>console.log(Constants.count);\nconsole.log(Utils.toLowerCase(&#039;Hello World&#039;));<\/code><\/pre>\n<h3>\u7ee7\u627f<\/h3>\n<p>\u7ee7\u627f\u662f\u2faf\u5411\u5bf9\u8c61\u7f16\u7a0b\u4e2d\u7684\u91cd\u8981\u673a\u5236\uff0c\u5141\u8bb8\u2f00\u4e2a\u7c7b\uff08\u2f26\u7c7b\u6216\u6d3e\u2f63\u7c7b\uff09\u7ee7\u627f\u53e6\u2f00\u4e2a\u7c7b\uff08\u2f57\u7c7b\u6216\u57fa\u7c7b\uff09<br \/>\n\u7684\u5c5e\u6027\u548c\u2f45\u6cd5\u3002\u2f26\u7c7b\u53ef\u4ee5\u76f4\u63a5\u4f7f\u2f64\u2f57\u7c7b\u7684\u7279\u6027\uff0c\u5e76\u6839\u636e\u9700\u8981\u6dfb\u52a0\u65b0\u7684\u7279\u6027\u6216\u8986\u76d6\u73b0\u6709\u7684\u7279\u6027\u3002\u8fd9<br \/>\n\u79cd\u673a\u5236\u8d4b\u4e88\u2faf\u5411\u5bf9\u8c61\u7a0b\u5e8f\u826f\u597d\u7684\u6269\u5c55\u6027\u3002<br \/>\n\u4e0b\u2faf\u901a\u8fc7\u2f00\u4e2a\u4f8b\u2f26\u6f14\u793a\u7ee7\u627f\u7684\u7279\u6027<\/p>\n<pre class=\"prettyprint linenums\" ><code>class Student extends Person {\n classNumber: string;\n constructor(id: number, name: string, classNumber: string) {\n super(id, name);\n this.classNumber = classNumber;\n }\n introduce(): string {\n return super.introduce()+`, and I am a student`;\n }\n}\nlet student = new Student(1,&#039;xiaoming&#039;,&#039;\u4e09\u5e74\u2f06\u73ed&#039;);\nconsole.log(student.introduce());<\/code><\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u7c7b\u7684\u7ee7\u627f\u9700\u8981\u4f7f\u2f64\u5173\u952e\u5b57 extends<\/li>\n<li>\u2f26\u7c7b\u6784\u9020\u5668\u4e2d\u9700\u4f7f\u2f64 super() \u8c03\u2f64\u2f57\u7c7b\u6784\u9020\u5668\u5bf9\u7ee7\u627f\u2f83\u2f57\u7c7b\u7684\u5c5e\u6027\u8fdb\u2f8f\u521d\u59cb\u5316\u3002<\/li>\n<li>\u5728\u2f26\u7c7b\u4e2d\u53ef\u4ee5\u4f7f\u2f64 this \u5173\u952e\u5b57\u8bbf\u95ee\u7ee7\u627f\u2f83\u2f57\u7c7b\u7684\u5c5e\u6027\u548c\u2f45\u6cd5\u3002<\/li>\n<li>\u5728\u2f26\u7c7b\u4e2d\u53ef\u4ee5\u4f7f\u2f64 super \u5173\u952e\u5b57\u8bbf\u95ee\u2f57\u7c7b\u5b9a\u4e49\u7684\u2f45\u6cd5\u3002<\/li>\n<\/ul>\n<h2>ArkTS \u5feb\u901f\u5165\u95e8<\/h2>\n<h3>\u58f0\u660e\u5f0f UI &amp; \u7ec4\u4ef6\u5316<\/h3>\n<p>\u58f0\u660e\u5f0f UI \u662f\u4e00\u79cd\u7f16\u5199\u7528\u6237\u754c\u9762\u7684\u8303\u5f0f\u3002<\/p>\n<ul>\n<li>\u5b9a\u4e49\u754c\u9762\u72b6\u6001<\/li>\n<li>\u63cf\u8ff0\u754c\u9762\u663e\u793a\u6548\u679c<\/li>\n<li>\u6539\u53d8\u72b6\u6001<\/li>\n<\/ul>\n<h2>\u8bed\u6cd5\u8bf4\u660e<\/h2>\n<h3>\u58f0\u660e\u7ec4\u4ef6<\/h3>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/10\/2024103023223748.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/10\/2024103023223748.png\" alt=\"\" \/><\/p><\/noscript>\n<h3>\u81ea\u5b9a\u4e49\u7ec4\u4ef6<\/h3>\n<ul>\n<li>\u8f93\u5165 comp ( \u7b80\u5199 ) \u56de\u8f66<\/li>\n<li>\u7ed9\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u4f20\u53c2\u4e00\u5b9a\u662f\u4e2a\u5bf9\u8c61<\/li>\n<\/ul>\n<h3>\u6761\u4ef6\u6e32\u67d3<\/h3>\n<h3>\u5faa\u73af\u6e32\u67d3<\/h3>\n<pre class=\"prettyprint linenums\" ><code>ForEach(\n arr: any[],\n itemGenerator: (item: any, index?: number) =&gt; void,\n keyGenerator?: (item: any, index?: number) =&gt; string\n)<\/code><\/pre>\n<h4>keyGenerator\uff08\u53ef\u9009\uff09\uff1a<\/h4>\n<ul>\n<li>\n<p>key\u2f63\u6210\u51fd\u6570\uff0c\u2f64\u4e8e\u4e3a arr \u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u6570\u636e\u9879\u2f63\u6210\u552f\u2f00\u7684 key\u3002<\/p>\n<\/li>\n<li>\n<p>key \u7684\u4f5c\u2f64<\/p>\n<pre class=\"prettyprint linenums\" ><code>ForEach \u5728\u6570\u7ec4\u53d1\u2f63\u53d8\u5316\uff08\u4fee\u6539\u6570\u7ec4\u5143\u7d20\u6216\u8005\u5411\u6570\u7ec4\u589e\u52a0\u6216\u5220\u9664\u5143\u7d20\uff09\u65f6\uff0c\u9700\u8981\u91cd\u65b0\u6e32\n\u67d3\u7ec4\u4ef6\u5217\u8868\uff0c\u5728\u91cd\u65b0\u6e32\u67d3\u65f6\uff0c\u5b83\u4f1a\u5c3d\u91cf\u590d\u2f64\u539f\u6765\u7684\u7ec4\u4ef6\u5bf9\u8c61\uff0c\u2f7d\u4e0d\u662f\u4e3a\u6bcf\u4e2a\u5143\u7d20\u90fd\u91cd\u65b0\u521b\n\u5efa\u7ec4\u4ef6\u5bf9\u8c61\u3002key \u7684\u4f5c\u2f64\u5c31\u662f\u8f85\u52a9 ForEach \u5b8c\u6210\u7ec4\u4ef6\u5bf9\u8c61\u7684\u590d\u2f64\u3002\n\u5177\u4f53\u903b\u8f91\u5982\u4e0b\uff1a\nForEach \u5728\u8fdb\u2f8f\u521d\u6b21\u6e32\u67d3\u65f6\uff0c\u4f1a\u4f7f\u2f64keyGenerator \u4e3a\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u2f63\u6210\u2f00\u4e2a\u552f\u2f00\n\u7684 key\uff0c\u5e76\u5c06 key \u4f5c\u4e3a\u7ec4\u4ef6\u5bf9\u8c61\u7684\u6807\u8bc6\u3002\u5f53\u6570\u7ec4\u53d1\u2f63\u53d8\u5316\u5bfc\u81f4 ForEach \u9700\u8981\u91cd\u65b0\u6e32\u67d3\n\u65f6\uff0c ForEach \u4f1a\u518d\u6b21\u4f7f\u2f64keyGenerator \u4e3a\u6bcf\u4e2a\u5143\u7d20\u91cd\u65b0\u2f63\u6210\u2f00\u904d key\uff0c\u7136\u540e ForEac\nh \u4f1a\u68c0\u67e5\u65b0\u2f63\u6210\u7684 key \u5728\u4e0a\u6b21\u6e32\u67d3\u65f6\u662f\u5426\u5df2\u7ecf\u5b58\u5728\uff0c\u82e5\u5b58\u5728\uff0c ForEach \u5c31\u4f1a\u8ba4\u4e3a\u8fd9\u4e2a\nkey \u5bf9\u5e94\u7684\u6570\u7ec4\u5143\u7d20\u6ca1\u6709\u53d1\u2f63\u53d8\u5316\uff0c\u90a3\u5b83\u5c31\u4f1a\u76f4\u63a5\u590d\u2f64\u8fd9\u4e2a key \u6240\u5bf9\u5e94\u7684\u7ec4\u4ef6\u5bf9\u8c61\uff1b\u82e5\u4e0d\n\u5b58\u5728\uff0c ForEach \u5c31\u4f1a\u8ba4\u4e3a\u8fd9\u4e2a key \u5bf9\u5e94\u7684\u5143\u7d20\u53d1\u2f63\u4e86\u53d8\u5316\uff0c\u6216\u8005\u8be5\u5143\u7d20\u4e3a\u65b0\u589e\u5143\u7d20\uff0c\u6b64\n\u65f6\uff0c\u5c31\u4f1a\u4e3a\u8be5\u5143\u7d20\u91cd\u65b0\u521b\u5efa\u2f00\u4e2a\u7ec4\u4ef6\u5bf9\u8c61\u3002<\/code><\/pre>\n<\/li>\n<li>\n<p>\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7 keyGenerator \u51fd\u6570\u2f83\u5b9a\u4e49 key \u7684\u2f63\u6210\u89c4\u5219\u3002\u5982\u679c\u5f00\u53d1\u8005\u6ca1\u6709\u5b9a\u4e49 keyGenerator \u51fd\u6570\uff0c\u5219\u7cfb\u7edf\u4f1a\u4f7f\u2f64\u9ed8\u8ba4\u7684 key\u2f63\u6210\u51fd\u6570\uff0c\u5373<\/p>\n<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>(item: any, index: number) =&gt; { return index + &#039;__&#039; + JSON.stringify(ite\nm); }<\/code><\/pre>\n<ul>\n<li>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u9ed8\u8ba4\u7684 key\u2f63\u6210\u51fd\u6570\uff0c\u4f1a\u5bfc\u81f4\u754c\u2faf\u6e32\u67d3\u6548\u7387\u4f4e\u4e0b\uff0c\u6b64\u65f6\u53ef\u8003\u8651\u901a\u8fc7 keyGenerator \u51fd\u6570\u2f83\u5b9a\u4e49\u2f63\u6210\u903b\u8f91\uff0c\u4f8b\u5982\u5982\u4e0b\u573a\u666f:<br \/>\n<strong>\u72b6\u6001\u53d8\u91cf\u6570\u7ec4\u5b9a\u4e49\u5982\u4e0b<\/strong><\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>@State arr:string[] = [&quot;zhangsan&quot;,&quot;lisi&quot;,&quot;wangwu&quot;]<\/code><\/pre>\n<p><strong>ForEach \u8bed\u53e5\u5982\u4e0b<\/strong><\/p>\n<pre class=\"prettyprint linenums\" ><code>Column(){\n ForEach(this.arr,(item)=&gt;{ Text(item) })\n}<\/code><\/pre>\n<ul>\n<li>\u521d\u6b21\u6e32\u67d3\u65f6\uff0c\u6bcf\u4e2a\u5143\u7d20\u5bf9\u5e94\u7684 key \u4f9d\u6b21\u4e3a 0<strong>&quot;zhagnsan&quot; \u3001 1<\/strong>&quot;lisi&quot; \u3001 2<strong>&quot;wangwu&quot; \u3002\u82e5\u73b0\u6709\u2f00\u4e2a\u64cd\u4f5c\u662f\u5411 arr \u6570\u7ec4\u5934\u90e8\u63d2\u2f0a\u65b0\u7684\u5143\u7d20\uff0c\u4f8b\u5982\u65b0\u5143\u7d20\u4e3a wanger\uff0c\u6309\u7167\u9ed8\u8ba4\u7684 key\u2f63\u6210\u903b\u8f91\uff0c\u63d2\u2f0a\u65b0\u5143\u7d20\u4e4b\u540e\u6bcf\u4e2a\u5143\u7d20\u7684 key \u5c31\u4f1a\u4f9d\u6b21\u53d8\u4e3a 0<\/strong>&quot;wanger&quot; \u3001 1<strong>&quot;zhagnsan&quot; \u3001 2<\/strong>&quot;lisi&quot; \u3001 3__&quot;wangwu&quot; \uff0c\u4e5f\u5c31\u662f\u6240\u6709\u5143\u7d20\u7684 key \u90fd\u53d1\u2f63\u4e86\u53d8\u5316\uff0c\u56e0\u6b64 UI \u754c\u2faf\u66f4\u65b0\u65f6\u9700\u8981\u4e3a\u6bcf\u4e2a\u5143\u7d20\u90fd\u91cd\u65b0\u521b\u5efa\u7ec4\u4ef6\u5bf9\u8c61\uff0c\u5373\u4fbf\u539f\u6709\u7684\u5143\u7d20\u6ca1\u6709\u53d1\u2f63\u53d8\u5316\u4e5f\u2f46\u6cd5\u590d\u2f64\u4e4b\u524d\u7684\u7ec4\u4ef6\uff0c\u8fd9\u6837\u2f00\u6765\u5c31\u5bfc\u81f4\u4e86\u6027\u80fd\u6d6a\u8d39\u3002\u6b64\u65f6\u6211\u4eec\u5c31\u53ef\u4ee5\u8003\u8651\u63d0\u4f9b\u7b2c\u4e09\u4e2a\u53c2\u6570\uff0c\u5982\u4e0b<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>Column(){\n ForEach(this.arr, (item)=&gt;{ Text(item) }, item =&gt; JSON.stringify(item))\n}<\/code><\/pre>\n<h2>\u56fe\u7247 UI \u7ec4\u4ef6\u5e38\u7528\u5c5e\u6027<\/h2>\n<p>1vp \u76f8\u5f53\u4e8e\u50cf\u7d20\u5bc6\u5ea6\u4e3a 160ppi \u7684\u5c4f\u5e55\u4e0a\u7684 1px<\/p>\n<p>DPI  480<br \/>\n<img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/10\/2024110116421126.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/10\/2024110116421126.png\" alt=\"\" \/><\/p><\/noscript>\n<pre class=\"prettyprint linenums\" ><code class=\"language-index.ets\">@Entry\n@Component\nstruct Index {\n  @State message: string = &#039;Hello ArkTs&#039;\n\n  build() {\n    Column({ space: 20 }) {\n      Row({ space: 20 }) {\n        Column() {\n          Image($r(&#039;app.media.icon&#039;)).width(&#039;450px&#039;).height(&#039;450px&#039;)\n          Text(&#039;450px&#039;)\n        }\n        Column(){\n          Image($r(&#039;app.media.icon&#039;))\n            .width(&#039;150vp&#039;).height(&#039;150vp&#039;)\n          Text(&#039;150vp&#039;)\n\n        }\n      }\n    }.width(&#039;100%&#039;).height(&#039;100%&#039;).justifyContent(FlexAlign.Center)\n  }\n}<\/code><\/pre>\n<h3>\u56fe\u7247\u7f29\u653e<\/h3>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/11\/2024110117272310.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/11\/2024110117272310.png\" alt=\"\" \/><\/p><\/noscript>\n<h3>\u56fe\u7247\u63d2\u503c<\/h3>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/11\/2024110117334067.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/11\/2024110117334067.png\" alt=\"\" \/><\/p><\/noscript>\n<h2>Text \u6587\u672c\u7ec4\u4ef6<\/h2>\n<pre class=\"prettyprint linenums\" ><code>@Entry\n@Component\nstruct Index {\n  @State message: string = &#039;Hello ArkTs&#039;\n\n  build() {\n    Column({ space: 20 }) {\n     \/\/\u5b57\u7b26\u4e32\u7c7b\u578b\n      Text(&#039;\u60a8\u597d,\u9e3f\u8499&#039;).fontSize(50)\n\n      \/\/Resource \u7c7b\u578b\n      Text($r(&#039;app.string.greeting&#039;)).fontSize(50)\n    }.width(&#039;100%&#039;).height(&#039;100%&#039;).justifyContent(FlexAlign.Center)\n  }\n}<\/code><\/pre>\n<ul>\n<li>base\/element\/sting.json<\/li>\n<li>zh_CN\/element\/sting.json<\/li>\n<li>en_US\/element\/sting.json<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>    {\n      &quot;name&quot;: &quot;greeting&quot;,\n      &quot;value&quot;: &quot;\u60a8\u597d,\u9e3f\u8499&quot;\/\/hello harmony\n    }<\/code><\/pre>\n<h3>fontSize \u5b57\u4f53\u5927\u5c0f<\/h3>\n<p>1fp=3px<br \/>\n\u76f4\u63a5\u5199 50 \u5219\u662f 50fp<\/p>\n<h3>fontWeight \u5b57\u4f53\u7c97\u7ec6<\/h3>\n<p>\u53d6\u503c\u8303\u56f4\u4e3a [ 100,900 ] , \u9ed8\u8ba4\u4e3a 400<\/p>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/11\/202411012201525.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/11\/202411012201525.png\" alt=\"\" \/><\/p><\/noscript>\n<ul>\n<li>\u5b57\u7b26\u4e32\u7c7b\u578b, 'bolder'<\/li>\n<\/ul>\n<h3>\u5b57\u4f53\u989c\u8272<\/h3>\n<ul>\n<li>Color \u7c7b\u578b Color.Green<\/li>\n<li>string \u7c7b\u578b rgb(0,128,0) \u6216\u8005 ' #008000 '<\/li>\n<li>number \u7c7b\u578b  \u4f7f\u7528 16 \u8fdb\u5236\u7684\u6570\u5b57\u8bbe\u7f6e rgb \u683c\u5f0f\u7684\u989c\u8272, \u5177\u4f53\u5199\u6cd5\u4e3a 0x008000<\/li>\n<li>Resource \u7c7b\u578b<\/li>\n<\/ul>\n<h2>\u5207\u6362\u6309\u94ae Toggle<\/h2>\n<pre class=\"prettyprint linenums\" ><code>Toggle( options:{ type: ToggleType, isOn?:boolean } )<\/code><\/pre>\n<ul>\n<li>ToggleType \u679a\u4e3e\u7c7b\u578b\uff1a<br \/>\nSwitch   Checkbox   Button<\/li>\n<li>isOn \u5c5e\u6027\u7528\u4e8e\u8bbe\u7f6e Toggle \u7ec4\u4ef6\u7684\u72b6\u6001<\/li>\n<\/ul>\n<h3>\u9009\u4e2d\u72b6\u6001\u80cc\u666f\u8272<\/h3>\n<ul>\n<li>selectedColor()<\/li>\n<\/ul>\n<h3>\u6ed1\u5757\u989c\u8272<\/h3>\n<ul>\n<li>switchPointColor()<\/li>\n<\/ul>\n<h3>onChange()\u65b9\u6cd5  (isOn)=&gt;{}<\/h3>\n<h2>\u6587\u672c\u8f93\u5165 TextInput \u7ec4\u4ef6<\/h2>\n<ul>\n<li>\u5149\u6807\u6837\u5f0f caretColor() <\/li>\n<li>placeholderFont() \u548c placeholderColor() \u8bbe\u7f6e placeholder \u7684\u6837\u5f0f,<\/li>\n<\/ul>\n<h2>Progress \u8fdb\u5ea6\u6761\u7ec4\u4ef6<\/h2>\n<pre class=\"prettyprint linenums\" ><code>Progress({value:this.value,total:this.total,type:ProgressType.ScaleRing}).style({scaleWidth:1,strokeWidth:10,scaleCount:60})<\/code><\/pre>\n<h2>\u5f39\u7a97<\/h2>\n<h3>\u6d88\u606f\u63d0\u793a Toast<\/h3>\n<ul>\n<li>\u7b80\u77ed\u7684\u6d88\u606f\u6216\u63d0\u793a<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>Button(&#039;\u63d0\u793a\u4fe1\u606f&#039;).onClick(() =&gt; {\n        promptAction.showToast({\n          message: &#039;\u7f51\u7edc\u8fde\u63a5\u5df2\u65ad\u5f00&#039;,\n          duration: 2000,\n          bottom: 50\n        })\n      })<\/code><\/pre>\n<h3>AlertDialog\uff08\u8b66\u544a\u5bf9\u8bdd\u6846\uff09<\/h3>\n<ul>\n<li>\u2f64\u4e8e\u5411\u2f64\u6237\u53d1\u51fa\u8b66\u544a\u6216\u786e\u8ba4\u64cd\u4f5c\u7684\u63d0\u793a\uff0c\u786e\u4fdd\u2f64\u6237\u5728\u654f\u611f\u64cd\u4f5c\u524d\u8fdb\u2f8f\u786e\u8ba4\u3002<\/li>\n<\/ul>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/11\/2024111014510165.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/11\/2024111014510165.png\" alt=\"\" \/><\/p><\/noscript>\n<pre class=\"prettyprint linenums\" ><code>      Button(&#039;\u5220\u9664&#039;).backgroundColor(Color.Red)\n        .onClick(()=&gt;{\n          AlertDialog.show({\n            title:&#039;\u5220\u9664\u8be5\u8bb0\u5f55?&#039;, \/\/\u5f39\u7a97\u6807\u9898\n            message:&#039;\u5220\u9664\u540e\u65e0\u6cd5\u6062\u590d, \u60a8\u786e\u8ba4\u8981\u5220\u9664\u5417?&#039;,\/\/\u5f39\u7a97\u4fe1\u606f\n            autoCancel:true,\/\/\u70b9\u51fb\u906e\u7f69\u5c42\u65f6,\u662f\u5426\u5173\u95ed\u5f39\u7a97\n            alignment:DialogAlignment.Bottom,\/\/\u5f39\u7a97\u4f4d\u7f6e\n            offset:{dx:0,dy:-20},\/\/\u76f8\u5bf9\u4e8e\u5f39\u7a97\u4f4d\u7f6e\u7684\u504f\u79fb\u91cf\n            primaryButton:{\/\/\u4e3b\u8981\u6309\u94ae, \u4f4d\u4e8e\u5de6\u4fa7\n              value:&#039;\u786e\u8ba4&#039;,\/\/\u6309\u94ae\u5185\u5bb9\n              fontColor:Color.Red,\/\/\u5b57\u4f53\u989c\u8272\n              action:()=&gt;{\/\/\u70b9\u51fb\u56de\u8c03\n                console.log(&#039;\u786e\u8ba4\u5220\u9664&#039;)\n              }\n            },\n            secondaryButton:{\/\/\u6b21\u8981\u6309\u94ae,\u4f4d\u4e8e\u53f3\u4fa7\n              value:&#039;\u53d6\u6d88&#039;,\n              action:()=&gt;{\n                console.log(&#039;\u70b9\u51fb\u53d6\u6d88&#039;)\n              }\n\n            },\n            cancel:()=&gt;{\/\/\u70b9\u51fb\u906e\u7f69\u5c42\u53d6\u6d88\u65f6\u7684\u56de\u8c03\n              console.log(&#039;closed callbacks&#039;)\n            }\n          })\n        })<\/code><\/pre>\n<h3>\u64cd\u4f5c\u5217\u8868\u5f39\u7a97<\/h3>\n<h3>\u9009\u62e9\u5668\u5f39\u7a97<\/h3>\n<h3>\u81ea\u5b9a\u4e49\u5f39\u7a97<\/h3>\n<pre class=\"prettyprint linenums\" ><code>@Entry\n@Component\nstruct Index {\n  @State answer: string = &#039;?&#039;;\n  controller: CustomDialogController = new CustomDialogController({\n    builder: TextInputDialog({\n      confirm:(value)=&gt;{\n        this.answer=value;\n      }\n    }),\n    alignment:DialogAlignment.Bottom,\n    offset:{dx:0,dy:-20}\n  })\n\n  build() {\n    Column({ space: 50 }) {\n      Row() {\n        Text(&#039;1+1=&#039;)\n          .fontWeight(FontWeight.Bold)\n          .fontSize(30)\n        Text(this.answer)\n          .fontWeight(FontWeight.Bold)\n          .fontSize(30)\n      }\n\n      Button(&#039;\u4f5c\u7b54&#039;)\n        .onClick(() =&gt; {\n          this.controller.open()\n          \/\/ \/\/\u5f39\u7a97\n          \/\/ TextPickerDialog.show({\n          \/\/   range: [&#039;1&#039;, &#039;2&#039;, &#039;3&#039;, &#039;4&#039;],\n          \/\/   onAccept: (value) =&gt; {\n          \/\/     \/\/ this.answer=value.value;\n          \/\/   }\n          \/\/ })\n        })\n    }.width(&#039;100%&#039;)\n    .height(&#039;100%&#039;)\n    .justifyContent(FlexAlign.Center)\n  }\n}\n\n@CustomDialog\nstruct TextInputDialog {\n  controller: CustomDialogController = new CustomDialogController({\n    builder: TextInputDialog()\n  })\n  confirm:(value:string)=&gt;void=()=&gt;{}\n  value:string=&#039;&#039;\n  build() {\n    Column({space:20}) {\n      Text(&#039;\u8bf7\u8f93\u5165\u4f60\u7684\u7b54\u6848&#039;)\n      TextInput({ placeholder: &#039;\u8bf7\u8f93\u5165\u6570\u5b57&#039; })\n        .type(InputType.Number)\n        .onChange((value=&gt;{\n          this.value=value\n        }))\n      Row({space:50}) {\n        Button(&#039;\u53d6\u6d88&#039;)\n          .onClick(() =&gt; {\n            this.controller.close()\n          })\n        Button(&#039;\u786e\u8ba4&#039;).onClick(() =&gt; {\n          this.confirm(this.value)\n          this.controller.close()\n        })\n      }\n    }.padding(20)\n  }\n}<\/code><\/pre>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/11\/202411182252413.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/11\/202411182252413.png\" alt=\"\" \/><\/p><\/noscript>\n<h2>\u7f16\u7a0b\u6280\u5de7<\/h2>\n<h3>\u6837\u5f0f\u590d\u7528<\/h3>\n<p><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/11\/2024111823015769.png\"  alt=\"\" \/><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2024\/11\/2024111823015769.png\" alt=\"\" \/><\/p><\/noscript>\n<ul>\n<li>@Extend \u65b9\u6cd5\u53ea\u80fd\u5b9a\u4e49\u5728\u5168\u5c40,\u4ec5\u9650\u5f53\u524d\u6587\u4ef6<\/li>\n<li>\u7528\u4e8e\u7279\u5b9a\u7c7b\u578b\u7684\u7ec4\u4ef6, \u53ef\u5305\u542b\u8be5\u7ec4\u4ef6\u7684\u4e13\u6709\u5c5e\u6027\u65b9\u6cd5\u548c\u4e13\u6709\u4e8b\u4ef6\u65b9\u6cd5<\/li>\n<li>\u652f\u6301\u53c2\u6570<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>@Extend(Button) function buttonStyleFunc(color:Color){\n  .backgroundColor(color)\n}<\/code><\/pre>\n<h3>UI \u7ed3\u6784\u590d\u7528 Builder<\/h3>\n<ul>\n<li>\u7ec4\u4ef6\u5185, \u5168\u5c40 \u5bfc\u51fa\u5728 function \u524d\u9762\u52a0 export\n<pre class=\"prettyprint linenums\" ><code>@Builder compButtonBuilder(icon:Resource,text:string,callback:()=&gt;void){\nButton(){\n  Row({space:10}){\n    Image(icon).width(25).height(25)\n    Text(text).fontColor(Color.White).fontSize(25)\n  }\n} .width(200)\n.height(40).onClick(callback)<\/code><\/pre>\n<\/li>\n<li>\u82e5\u590d\u7528\u7684 UI \u7ed3\u6784\u6ca1\u6709\u72b6\u6001, \u63a8\u8350\u4f7f\u7528@Builder \u65b9\u6cd5, \u5426\u5219\u4f7f\u7528\u81ea\u5b9a\u4e49\u7ec4\u4ef6<\/li>\n<\/ul>\n<h3>UI \u7ed3\u6784\u590d\u7528 BuilderParam<\/h3>\n<h2>\u5e38\u7528\u5e03\u5c40<\/h2>\n<h3>\u7ebf\u6027\u5e03\u5c40<\/h3>\n<h3>\u5c42\u53e0\u5e03\u5c40<\/h3>\n<h3>\u5f39\u6027\u5e03\u5c40<\/h3>\n<h3>\u7f51\u7edc\u5e03\u5c40<\/h3>\n<h3>\u5217\u8868\u5e03\u5c40<\/h3>\n<h2>\u7ec4\u4ef6\u72b6\u6001\u7ba1\u7406<\/h2>\n","protected":false},"excerpt":{"rendered":"<p>HarmonyOS \u4e09\u5927\u7279\u6027 \u786c\u4ef6\u4e92\u52a9\uff0c\u8d44\u6e90\u5171\u4eab \u4e00\u6b21\u5f00\u53d1\uff0c\u591a\u7aef\u90e8\u7f72 \u7edf\u4e00 OS\uff0c\u5f39\u6027\u90e8\u7f72 \u786c\u4ef6\u4e92\u52a9\uff0c\u8d44\u6e90\u5171\u4eab [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-4735","post","type-post","status-publish","format-standard","hentry","category-web"],"_links":{"self":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts\/4735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4735"}],"version-history":[{"count":52,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts\/4735\/revisions"}],"predecessor-version":[{"id":4837,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts\/4735\/revisions\/4837"}],"wp:attachment":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}