{"id":2813,"date":"2023-07-11T12:04:03","date_gmt":"2023-07-11T04:04:03","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=2813"},"modified":"2023-07-11T12:04:03","modified_gmt":"2023-07-11T04:04:03","slug":"h5-%e5%bc%80%e5%8f%91-android%e6%98%af%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0%e7%9a%84%e5%91%a2%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/2813\/","title":{"rendered":"h5 \u5f00\u53d1 android\u662f\u600e\u4e48\u5b9e\u73b0\u7684\u5462\uff1f"},"content":{"rendered":"

HTML5\u662f\u4e00\u79cd\u6807\u8bb0\u8bed\u8a00\uff0c\u53ef\u7528\u4e8e\u521b\u5efa\u7f51\u9875\u548c\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e2d\uff0cHTML5\u88ab\u5e7f\u6cdb\u4f7f\u7528\uff0c\u7279\u522b\u662f\u5728Android\u5e73\u53f0\u4e0a\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528HTML5\u8fdb\u884cAndroid\u5f00\u53d1\u3002<\/p>\n

HTML5\u662f\u4e00\u79cd\u57fa\u4e8eWeb\u7684\u6280\u672f\uff0c\u53ef\u4ee5\u7528\u4e8e\u5f00\u53d1\u8de8\u5e73\u53f0\u5e94\u7528\u7a0b\u5e8f\u3002Android\u5e73\u53f0\u4e0a\u7684HTML5\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5b89\u5353app\u4e00\u952e\u751f\u6210<\/a>\u4f7f\u7528Android WebView\u7ec4\u4ef6\u6765\u8fd0\u884c\u3002WebView\u662f\u4e00\u4e2a\u5185\u7f6e\u7684\u6d4f\u89c8\u5668\uff0c\u53ef\u4ee5\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5d4c\u5165Web\u9875\u9762\u3002<\/p>\n

\u5728Android\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528HTML5\u4e3b\u8981\u5206\u4e3a\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n

1. \u4f7f\u7528WebView\u7ec4\u4ef6\u5c06HTML5\u9875\u9762\u5d4c\u5165\u5230Android\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002<\/p>\n

2. \u4f7f\u7528Cordova\u6846\u67b6\u5c06HTML5\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210Android\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u7b2c\u4e00\u79cd\u65b9\u5f0f\u662f\u6700\u7b80\u5355\u7684\u65b9\u5f0f\uff0c\u53ea\u9700\u5c06HTML5\u9875\u9762\u52a0\u8f7d\u5230WebView\u7ec4\u4ef6\u4e2d\u5373\u53ef\u3002\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n

“`<\/p>\n

WebView webView = (WebView) findViewById(R.id.webView);<\/p>\n

webView.loadUrl(“file:\/\/\/android_asset\/index.html”);<\/p>\n

“`<\/p>\n

\u4e0a\u9762\u7684\u4ee3\u7801\u5c06index.html\u6587\u4ef6\u52a0\u8f7d\u5230WebView\u7ec4\u4ef6\u4e2d\u3002\u53ef\u4ee5\u5728assets\u6587\u4ef6\u5939\u4e2d\u653e\u7f6eHTML5\u9875\u9762\u3002<\/p>\n

\u7b2c\u4e8c\u79cd\u65b9\u5f0f\u662f\u4f7f\u7528Cordova\u6846\u67b6\u5c06HTML5\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210Android\u5e94\u7528\u7a0b\u5e8f\u3002Cordova\u662f\u4e00\u4e2a\u5f00\u6e90\u6846\u67b6\uff0c\u7528\u4e8e\u521b\u5efa\u8de8\u5e73\u53f0\u79fb\u52a8\u5e94\u7528<\/p>\n

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

\u7a0b\u5e8f\u3002\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n

“`<\/p>\n

cordova create hello com.example.hello HelloWorld<\/p>\n

cd hello<\/p>\n

cordova platform add android<\/p>\n

cordova build android<\/p>\n

“`<\/p>\n

\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3ahel\u7535\u8111\u81ea\u5236\u8f6f\u4ef6<\/a>lo\u7684Cordova\u9879\u76ee\uff0c\u5e76\u5c06\u5176\u6253\u5305\u6210Android\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n

\u4f7f\u7528HTML5\u8fdb\u884cAndroid\u5f00\u53d1\u7684\u597d\u5904\u662f\u53ef\u4ee5\u5feb\u901f\u5f00\u53d1\u8de8\u5e73\u53f0\u5e94\u7528\u7a0b\u5e8f\u3002HTML5\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5728\u591a\u4e2a\u5e73\u53f0\u4e0a\u8fd0\u884c\uff0c\u800c\u4e0d\u9700\u8981\u91cd\u65b0\u7f16\u5199\u4ee3\u7801\u3002\u6b64\u5916\uff0c\u4f7f\u7528HTML5\u8fdb\u884c\u5f00\u53d1\u8fd8\u53ef\u4ee5\u51cf\u5c11\u5f00\u53d1\u6210\u672c\u548c\u65f6\u95f4\u3002<\/p>\n

\u603b\u4e4b\uff0cHTML5\u662f\u4e00\u79cd\u975e\u5e38\u6709\u7528\u7684\u6280\u672f\uff0c\u53ef\u4ee5\u7528\u4e8e\u521b\u5efa\u8de8\u5e73\u53f0\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u3002\u5728Android\u5e73\u53f0\u4e0a\uff0c\u53ef\u4ee5\u4f7f\u7528WebView\u7ec4\u4ef6\u6216Cordova\u6846\u67b6\u6765\u5b9e\u73b0HTML5\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

HTML5\u662f\u4e00\u79cd\u6807\u8bb0\u8bed\u8a00\uff0c\u53ef\u7528\u4e8e\u521b\u5efa\u7f51\u9875\u548c\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e2d\uff0cHTML5\u88ab\u5e7f\u6cdb\u4f7f\u7528\uff0c\u7279\u522b\u662f\u5728Android\u5e73\u53f0\u4e0a\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528HTML5\u8fdb\u884cAndroid\u5f00\u53d1\u3002HTML5\u662f\u4e00\u79cd<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[5753,5752,14,90,914],"class_list":["post-2813","post","type-post","status-publish","format-standard","hentry","category-zuoapp","tag-android","tag-vue","tag-14","tag-90","tag-914"],"_links":{"self":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/2813","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\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/comments?post=2813"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/posts\/2813\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/media?parent=2813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/categories?post=2813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.com\/zhidian\/wp-json\/wp\/v2\/tags?post=2813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}