{"id":8596,"date":"2023-11-13T18:34:52","date_gmt":"2023-11-13T10:34:52","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=8596"},"modified":"2023-11-13T18:34:52","modified_gmt":"2023-11-13T10:34:52","slug":"%e5%a6%82%e4%bd%95%e5%b0%86html%e6%96%87%e4%bb%b6%e7%94%9f%e6%88%90app%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/8596\/","title":{"rendered":"\u5982\u4f55\u5c06html\u6587\u4ef6\u751f\u6210app\uff1f"},"content":{"rendered":"

\u5c06HTML\u6587\u4ef6\u751f\u6210APP\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u7f51\u9875\u5e94\u7528\u58f3\uff08\u5982PhoneGap\u6216Cordova\uff09\u6216\u4f7f\u7528WebView\u7ec4\u4ef6\u521b\u5efa\u4e00\u4e2a\u539f\u751f\u5e94\u7528\u3002\u8fd9\u91cc\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4e24\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e2a\u8f6c\u6362\u3002<\/p>\n

\u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528PhoneGap\/Cordova<\/p>\n

PhoneGap\u548cCordova\u5b9e\u8d28\u4e0a\u662f\u540c\u4e00\u4e2a\u9879\u76ee\uff0c\u7531Adobe\u8d5e\u52a9\u3002PhoneGap\u662fCordova\u7684\u5546\u4e1a\u7248\u672c\uff0c\u63d0\u4f9b\u4e86\u989d\u5916\u7684\u5de5\u5177\u548c\u670d\u52a1\u3002Cordova\u662f\u4e00\u4e2a\u5f00\u6e90\u9879\u76ee\uff0c\u53ef\u4ee5\u5c06HTML\u3001CSS\u548cJavaScript\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u539f\u751fAPP\u3002<\/p>\n

\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n

1. \u5b89\u88c5Node.js: \u9996\u5148\uff0c\u8bbf\u95eehttps:\/\/nodejs.org\uff0c\u4e0b\u8f7d\u5e76\u5b89\u88c5Node.js\u3002<\/p>\n

2. \u5b89\u88c5Cordova: \u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Cordova\uff1a<\/p>\n

“`<\/p>\n

npm install -g cordova<\/p>\n

“`<\/p>\n

3. \u521b\u5efaCordova\u9879\u76ee: \u5728\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\u4e2d\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Cordova\u9879\u76ee\uff1a<\/p>\n

“`<\/p>\n

cordova create myApp com.example.myapp MyApp<\/p>\n

“`<\/p>\n

\u8fd9\u5c06\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201capp \u5728\u7ebf\u751f\u6210\u5e73\u53f0<\/a>myApp\u201d\u7684\u6587\u4ef6\u5939\u3002<\/p>\n

4. \u8fdb\u5165\u9879\u76ee\u6587\u4ef6\u5939\uff1a<\/p>\n

“`<\/p>\n

cd myApp<\/p>\n

“`<\/p>\n

5. \u6dfb\u52a0\u5e73\u53f0: \u6839\u636e\u9700\u6c42\u6dfb\u52a0\u6240\u9700\u5e73\u53f0\uff0c\u4f8b\u5982Android\u6216iOS\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6dfb\u52a0\u76f8\u5e94\u5e73\u53f0\uff1a<\/p>\n

“`<\/p>\n

cordova platform add android<\/p>\n

cordova platform add ios<\/p>\n

“`<\/p>\n

\u6ce8\u610f\uff0c\u9700\u5728macOS\u4e0a\u6dfb\u52a0\u548c\u6784\u5efaiOS\u5e73\u53f0\u3002<\/p>\n

6. \u66ff\u6362HTML\uff0cCSS\u548cJavaScript\u6587\u4ef6: \u5c06\u4f60\u7684HTML\u6587\u4ef6\u53ca\u6240\u9700CSS\u548cJavaScript\u6587\u4ef6\u62f7\u8d1d\u81f3\u201cmyApp\/www\u201d\u6587\u4ef6\u5939\u4e0b\uff0c\u66ff\u6362\u9ed8\u8ba4\u6587\u4ef6\u3002<\/p>\n

7. \u751f\u6210APP: \u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6784\u5efa\u5e73\u53f0\u5bf9\u5e94\u7684APP\uff1a<\/p>\n

“`<\/p>\n

cordova build android<\/p>\n

cordova build ios<\/p>\n

“`<\/p>\n

\u6784\u5efa\u6210\u529f\u540e\uff0c\u60a8\u5c06\u5728”myApp\/platforms\/android\/app\/build\/outputs\/apk”\uff08Android\uff09\u6216”myApp\/platforms\/ios\/build\/device”\uff08iOS\uff09\u6587\u4ef6\u5939\u4e0b\u627e\u5230\u751f\u6210\u7684APP\u6587\u4ef6\u3002<\/p>\n

\u65b9\u6cd5\u4e8c\uff1a\u539f\u751fAPP\u4e2d\u4f7f\u7528WebView\u7ec4\u4ef6<\/p>\n

\u4ee5Andro<\/p>\n

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

id\u4e3a\u4f8b\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u4e00\u4e2aAndroid\u539f\u751f\u5e94\u7528\uff0c\u5e76\u4f7f\u7528WebView\u7ec4\u4ef6\u6765\u5448\u73b0HTML\u9875\u9762\u3002<\/p>\n

1. \u5b89\u88c5An\u5728\u7ebf\u751f\u6210app\u8f6f\u4ef6<\/a>droid Studio: \u8bbf\u95eehttps:\/\/developer.android.com\/studio\uff0c\u4e0b\u8f7d\u5e76\u5b89\u88c5Android Studio\u3002<\/p>\n

2. \u521b\u5efa\u65b0\u9879\u76ee: \u6253\u5f00Android Studio\uff0c\u9009\u62e9\u201c\u521b\u5efa\u65b0\u9879\u76ee\u201d\u3002\u9009\u62e9\u6240\u9700\u6a21\u677f\uff0c\u4e3a\u9879\u76ee\u547d\u540d\u5e76\u8bbe\u7f6e\u5176\u4ed6\u9009\u9879\u3002\u70b9\u51fb\u201c\u5b8c\u6210\u201d\u3002<\/p>\n

3. \u6dfb\u52a0WebView\u7ec4\u4ef6: \u5728\u9879\u76ee\u7684\u4e3b\u8981\u5e03\u5c40\u6587\u4ef6\uff08\u5982\u201cactivity_main.xml\u201d\uff09\u4e2d\uff0c\u6dfb\u52a0WebView\u7ec4\u4ef6\u3002<\/p>\n

“`<\/p>\n<\/p>\n

android:id=”@+id\/webview”<\/p>\n

android:layout_width=”match_parent”<\/p>\n

android:layout_height=”match_parent” \/><\/p>\n

“`<\/p>\n

4. \u52a0\u8f7dHTML\u6587\u4ef6: \u5c06HTML\u6587\u4ef6\uff08\u4ee5\u53caCSS\u548cJavaScript\u6587\u4ef6\uff09\u653e\u5165\u201capp\/src\/main\/assets\u201d\u6587\u4ef6\u5939\u4e0b\u3002\u7136\u540e\uff0c\u5728\u4e3b\u8981\u6d3b\u52a8\u7c7b\uff08\u5982\u201cMainActivity.java\u201d\uff09\u4e2d\uff0c\u52a0\u8f7d\u5e76\u663e\u793a\u8fd9\u4e2aHTML\u6587\u4ef6\u3002<\/p>\n

“`java<\/p>\n

import android.webkit.WebView;<\/p>\n

public class MainActivity extends AppCompatActivity {<\/p>\n

WebView webView;<\/p>\n

@Override<\/p>\n

protected void onCreate(Bundle savedInstanceState) {<\/p>\n

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

setContentView(R.layout.activity_main);<\/p>\n

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

webView.getSettings().setJavaScriptEnabled(true);<\/p>\n

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

}<\/p>\n

}<\/p>\n

“`<\/p>\n

5. \u751f\u6210APP: \u7ecf\u8fc7\u6784\u5efa\u548c\u6d4b\u8bd5\u540e\uff0c\u5728Android Studio\u4e2d\u9009\u62e9\u201c\u6784\u5efa\u201d\u83dc\u5355\uff0c\u7136\u540e\u70b9\u51fb\u201c\u751f\u6210APK\u201d\u751f\u6210APP\u3002\u751f\u6210\u7684APP\u6587\u4ef6\u5c06\u5728\u201capp\/build\/outputs\/apk\u201d\u6587\u4ef6\u5939\u4e0b\u3002<\/p>\n

\u540c\u7406\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5728iOS\u8bbe\u5907\u4e0a\u4f7f\u7528UIKit\u4e2d\u7684WKWebView\u7ec4\u4ef6\u521b\u5efa\u539f\u751fAPP\u3002<\/p>\n

\u603b\u4e4b\uff0c\u901a\u8fc7\u4f7f\u7528PhoneGap\/Cordova\u6216\u539f\u751fAPP\u4e2d\u7684WebView\u7ec4\u4ef6\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06HTML\u6587\u4ef6\u8f6c\u6362\u4e3aAPP\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5c06HTML\u6587\u4ef6\u751f\u6210APP\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u7f51\u9875\u5e94\u7528\u58f3\uff08\u5982PhoneGap\u6216Cordova\uff09\u6216\u4f7f\u7528WebView\u7ec4\u4ef6\u521b\u5efa\u4e00\u4e2a\u539f\u751f\u5e94\u7528\u3002\u8fd9\u91cc\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4e24\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e2a\u8f6c\u6362\u3002\u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528PhoneGap\/C<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[4882,16,3399,736,12478],"topic":[],"class_list":["post-8596","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-html--app","tag-16","tag-3399","tag-736","tag-app"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/8596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=8596"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/8596\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=8596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=8596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=8596"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=8596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}