{"id":14996,"date":"2023-11-30T11:45:52","date_gmt":"2023-11-30T03:45:52","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=14996"},"modified":"2023-11-30T11:45:52","modified_gmt":"2023-11-30T03:45:52","slug":"kotlin%e7%89%88%e5%ae%89%e5%8d%93app%e5%bc%80%e5%8f%91%e8%a6%81%e6%80%8e%e4%b9%88%e5%81%9a%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/14996\/","title":{"rendered":"kotlin\u7248\u5b89\u5353app\u5f00\u53d1\u8981\u600e\u4e48\u505a\uff1f"},"content":{"rendered":"

Kotlin\u662f\u4e00\u79cd\u57fa\u4e8eJVM\u7684\u9759\u6001\u7c7b\u578b\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u5b8c\u5168\u4e0eJava\u517c\u5bb9\uff0c\u5e76\u4e14\u5177\u5907\u66f4\u52a0\u7b80\u6d01\u3001\u5b89\u5168\u548c\u6613\u8bfb\u7684\u7279\u70b9\u3002\u56e0\u6b64\uff0c\u5b83\u88ab\u8d8a\u6765\u8d8a\u591a\u7684\u5b89\u5353\u5f00\u53d1\u8005\u6240\u91c7\u7528\u3002<\/p>\n

\u4e0b\u9762\u662f\u4e00\u4e9bKotlin\u7248\u5b89\u5353App\u5f00\u53d1\u7684\u539f\u7406\u548c\u8be6\u7ec6\u4ecb\u7ecd\uff1a<\/p>\n

1. \u57fa\u672c\u73af\u5883\u8bbe\u7f6e<\/p>\n

\u5728\u5f00\u59cbKotlin\u7248\u5b89\u5353\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u4e0b\u8f7d\u548c\u5b89\u88c5\u4ee5\u4e0b\u8f6f\u4ef6\uff1a<\/p>\n

– Android Studio<\/p>\n

– Kotlin\u63d2\u4ef6<\/p>\n

2. \u65b0\u5efa\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u8981\u521b\u5efa\u65b0\u7684Kotlin\u5b89\u5353\u5e94\u7528\u7a0b\u5e8f\uff0c\u8bf7\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n

– \u6253\u5f00Android Studio\uff0c\u5355\u51fb\u201c\u5f00\u59cb\u65b0\u7684Android Studio\u9879\u76ee\u201d\u3002<\/p>\n

– \u5728\u5f39\u51fa\u7684\u5bf9\u8bdd\u6846\u4e2d\uff0c\u6307\u5b9a\u5e94\u7528\u7a0b\u5e8f\u540d\u79f0\u548c\u5305\u540d\u79f0\uff0c\u4ee5\u53ca\u9879\u76ee\u4fdd\u5b58\u4f4d\u7f6e\uff0c\u7136\u540e\u5355\u51fb\u201c\u4e0b\u4e00\u6b65\u201d\u3002<\/p>\n

– \u5728\u4e0b\u4e00\u4e2a\u5c4f\u5e55\u4e0a\uff0c\u9009\u62e9\u201c\u7a7a\u767d\u6d3b\u52a8\u201d\uff0c\u7136\u540e\u5355\u51fb\u201c\u4e0b\u4e00\u6b65\u201d\u3002<\/p>\n

– \u5728\u4e0b\u4e00\u4e2a\u5c4f\u5e55\u4e0a\uff0c\u9009\u62e9\u201cKotlin\u201d\uff0c\u7136\u540e\u5355\u51fb\u201c\u5b8c\u6210\u201d\u6309\u94ae\u3002<\/p>\n

– \u5de5\u4f5c\u533a\u5c06\u6253\u5f00\uff0c\u5e76\u5305\u542b\u4e00\u4e2a\u7ed3\u6784\u826f\u597d\u7684\u9879\u76ee\uff0c\u5176\u4e2d\u5305\u62ec\u4e00\u4e2a\u4f7f\u7528Kotlin\u7f16\u5199\u7684\u4e3b\u8981\u6d3b\u52a8\u3002<\/p>\n

3. \u521b\u5efa\u65b0\u7684Kotlin\u7c7b<\/p>\n

\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Kotlin\u7c7b\uff0c\u8bf7\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n

– \u5728\u201c\u9879\u76ee\u201d\u7a97\u683c\u4e2d\uff0c\u5c55\u5f00\u201c\u5e94\u7528\u7a0b\u5e8f\u201d\u6587\u4ef6\u5939\uff0c\u7136\u540e\u53f3\u952e\u5355\u51fb\u201ckotlin\u201d\u6587\u4ef6\u5939\uff0c\u9009\u62e9\u201c\u65b0\u5efa\u7c7b\u201d\u3002<\/p>\n

– \u5728\u201c\u65b0\u5efa\u7c7b\u201d\u5bf9\u8bdd\u6846\u4e2d\uff0c\u8f93\u5165\u7c7b\u540d\u5e76\u9009\u62e9\u6240\u9700\u7684\u7236\u7c7b\uff0c\u4f8b\u5982\u201cFragment\u201d\u3002<\/p>\n

– \u5355\u51fb\u201c\u5b8c\u6210\u201d\u6309\u94ae\uff0c\u65b0\u7684Kotlin\u7c7b\u5c06\u5728\u201ckotlin\u201d\u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u3002<\/p>\n

4. \u7f16\u5199Kotlin\u4ee3\u7801<\/p>\n

Kotlin\u548cJava\u5f88\u7c7b\u4f3c\uff0c\u5b89\u5353app\u5236\u4f5c<\/a>\u56e0\u6b64\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b89\u5353\u6846\u67b6\u63d0\u4f9b\u7684\u6240\u6709\u7c7b\u548c\u65b9\u6cd5\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528Kotlin\u7f16\u5199\u7684\u7b80\u5355\u4f8b\u5b50\uff1a<\/p>\n

“`<\/p>\n

class MainActivity : AppCompatActivity() {<\/p>\n

override fun onCreate(savedInstanceState: Bundle?) {<\/p>\n

super.onCreate(savedInstanceState)<\/p>\n

setContentView(R.layout.acti\u5b89\u5353app\u5f00\u53d1\u5de5\u5177<\/a>vity_main)<\/p>\n

showMessage(“Hello World!”)<\/p>\n

}<\/p>\n

private fun showMessage(message: String) {<\/p>\n

Toast.makeText(this, message, Toast.LENGTH_SHORT).show()<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u6b64\u4ee3\u7801\u521b\u5efa\u7684\u6d3b\u52a8\u5305\u542b\u4e00\u4e2a\u6587\u672c\u89c6\u56fe\uff0c\u5176\u4e2d\u663e\u793a\u201cHello World\uff01\u201d\u7684\u6d88\u606f\u3002\u5728\u6d3b\u52a8\u7684onCr<\/p>\n

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

eate\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528setContentView\u65b9\u6cd5\u52a0\u8f7d\u5e03\u5c40\u6587\u4ef6\uff0c\u5e76\u8c03\u7528showMessage\u65b9\u6cd5\u6765\u663e\u793a\u6d88\u606f\u3002<\/p>\n

5. \u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f<\/p>\n

\u5f53\u60a8\u7f16\u5199\u5b8cKotlin\u4ee3\u7801\u5e76\u51c6\u5907\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u8bf7\u5355\u51fb\u201c\u8fd0\u884c\u201d\u6309\u94ae\uff0c\u5728\u6a21\u62df\u5668\u6216\u8fde\u63a5\u7684\u8bbe\u5907\u4e0a\u542f\u52a8\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u603b\u4e4b\uff0cKotlin\u7248\u5b89\u5353\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u662f\u4e00\u79cd\u975e\u5e38\u7b80\u5355\u3001\u76f4\u89c2\u548c\u5f3a\u5927\u7684\u65b9\u6cd5\uff0c\u5b8c\u5168\u53ef\u4ee5\u5e2e\u52a9\u60a8\u66f4\u8f7b\u677e\u5730\u521b\u5efa\u66f4\u9ad8\u6548\u548c\u5b89\u5168\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Kotlin\u662f\u4e00\u79cd\u57fa\u4e8eJVM\u7684\u9759\u6001\u7c7b\u578b\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u5b8c\u5168\u4e0eJava\u517c\u5bb9\uff0c\u5e76\u4e14\u5177\u5907\u66f4\u52a0\u7b80\u6d01\u3001\u5b89\u5168\u548c\u6613\u8bfb\u7684\u7279\u70b9\u3002\u56e0\u6b64\uff0c\u5b83\u88ab\u8d8a\u6765\u8d8a\u591a\u7684\u5b89\u5353\u5f00\u53d1\u8005\u6240\u91c7\u7528\u3002\u4e0b\u9762\u662f\u4e00\u4e9bKotlin\u7248\u5b89\u5353App\u5f00\u53d1\u7684\u539f\u7406\u548c\u8be6\u7ec6\u4ecb\u7ecd<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[22249,14,22248,593,90],"class_list":["post-14996","post","type-post","status-publish","format-standard","hentry","category-zuoapp","tag-app","tag-14","tag-vbapp","tag-593","tag-90"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/14996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=14996"}],"version-history":[{"count":1,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/14996\/revisions"}],"predecessor-version":[{"id":15008,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/14996\/revisions\/15008"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=14996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=14996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=14996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}