{"id":8855,"date":"2023-11-16T18:34:32","date_gmt":"2023-11-16T10:34:32","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=8855"},"modified":"2023-11-16T18:34:32","modified_gmt":"2023-11-16T10:34:32","slug":"%e5%ae%89%e5%8d%93%e7%bd%91%e9%a1%b5%e7%94%9f%e6%88%90app%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e7%9a%84","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/8855\/","title":{"rendered":"\u5b89\u5353\u7f51\u9875\u751f\u6210app\u5982\u4f55\u5b9e\u73b0\u7684?"},"content":{"rendered":"

\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u5b89\u5353\u7f51\u9875\u751f\u6210APP\u7684\u539f\u7406\u548c\u8be6\u7ec6\u4ecb\u7ecd\u3002\u73b0\u4ee3\u79fb\u52a8\u5e94\u7528\u5f00\u53d1\u9700\u8981\u5728\u591a\u4e2a\u5e73\u53f0\uff08\u5982\u5b89\u5353\u3001iOS\u7b49\uff09\u4e0a\u63d0\u4f9b\u76f8\u4f3c\u7684\u4f53\u9a8c\u3002\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u662f\u5c06\u73b0\u6709\u7684\u7f51\u9875\u5e94\u7528\u8f6c\u5316\u4e3a\u4e00\u4e2a\u53ef\u5728\u79fb\u52a8\u8bbe\u5907\u4e0a\u8fd0\u884c\u7684APP\uff0c\u8fd9\u6837\u53ef\u4ee5\u8282\u7701\u5f00\u53d1\u65f6\u95f4\u548c\u6210\u672c\uff0c\u63d0\u9ad8\u53ef\u7ef4\u62a4\u6027\u3002\u5b89\u5353\u5e73\u53f0\u4e2d\uff0c\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u7684\u5173\u952e\u6280\u672f\u662fWebView\u3002\u4e0b\u9762\uff0c\u8ba9\u6211\u4eec\u8be6\u7ec6\u4e86\u89e3\u8fd9\u4e00\u6280\u672f\u3002<\/p>\n

\u4e00\u3001\u539f\u7406\u4ecb\u7ecd<\/p>\n

\u5b89\u5353\u7f51\u9875\u751f\u6210APP\u7684\u57fa\u672c\u539f\u7406\u662f\u5229\u7528WebView\u8fd9\u4e2a\u7ec4\u4ef6\uff0c\u5c06\u73b0\u6709\u7684\u7f51\u9875\u5e94\u7528\uff08HTML\u3001CSS\u3001JavaScript\u7b49\u6587\u4ef6\uff09\u5d4c\u5165\u5230\u539f\u751f\u5b89\u5353\u5e94\u7528\u4e2d\u3002WebView\u662f\u5b89\u5353\u4e2d\u7684\u4e00\u4e2aUI\u7ec4\u4ef6\uff0c\u5b83\u53ef\u4ee5\u52a0\u8f7d\u548c\u663e\u793a\u7f51\u9875\u3002\u6b64\u5916\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217API\uff0c\u4f7f\u5f97\u539f\u751f\u5e94\u7528\u548c\u7f51\u9875\u5e94\u7528\u4e4b\u95f4\u53ef\u4ee5\u8fdb\u884c\u6570\u636e\u4ea4\u4e92\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5c06\u4e00\u4e2a\u7f51\u9875\u5e94\u7528\u5c01\u88c5\u6210\u4e00\u4e2a\u5b89\u5353APP\uff0c\u800c\u65e0\u9700\u4e3a\u6bcf\u4e2a\u5e73\u53f0\u7f16\u5199\u5b8c\u5168\u72ec\u7acb\u7684\u539f\u751f\u4ee3\u7801\u3002<\/p>\n

\u4e8c\u3001\u8be6\u7ec6\u4ecb\u7ecd<\/p>\n

1. \u521b\u5efa\u5b89\u5353\u9879\u76ee<\/p>\n

\u9996\u5148\uff0c\u60a8\u9700\u8981\u5728Android Studio\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b89\u5353\u9879\u76ee\u3002\u9879\u76ee\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u60a8\u9700\u8981\u5bfc\u5165WebView\u7ec4\u4ef6\u3002\u5728\u9879\u76ee\u7684build.gradle\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4f9d\u8d56\u9879\u7f51\u9875\u7248\u7684\u6e38\u620f\u600e\u4e48\u751f\u6210app<\/a>\uff0c\u7136\u540e\u540c\u6b65\u9879\u76ee\uff1a<\/p>\n

“`gradle<\/p>\n

dependencies {<\/p>\n

implementation ‘androidx.appcompat:appcompat:1.3.0’<\/p>\n

implementation ‘androidx.constraintlayout:constraintlayout:2.0.4’<\/p>\n

implementation ‘androidx.webkit:webkit:1.4.0’<\/p>\n

}<\/p>\n

“`<\/p>\n

2. \u6dfb\u52a0WebView\u7ec4\u4ef6<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u5728activity_main.xml\u6587\u4ef6\u4e2d\u6dfb\u52a0WebView\u7ec4\u4ef6\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u5c06\u4ee5\u4e0b\u4ee3\u7801\u6dfb\u52a0\u5230\u6587\u4ef6\u4e2d\uff1a<\/p>\n

“`xml<\/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

3. \u6dfb\u52a0Internet\u6743\u9650<\/p>\n

\u4e3a\u4e86\u8ba9\u5e94\u7528\u80fd\u591f\u8bbf\u95ee\u4e92\u8054\u7f51\uff0c\u60a8\u9700\u8981\u5728AndroidManifest.xml\u6587\u4ef6\u4e2d\u6dfb\u524d\u7aef\u6253\u5f00h5\u600e\u4e48\u751f\u6210app<\/a>\u52a0Internet\u6743\u9650\uff1a<\/p>\n

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

“`<\/p>\n

4. \u914d\u7f6eWebView<\/p>\n

\u5728MainActivity.java\u6587\u4ef6\u4e2d\uff0c\u8bbe\u7f6eWebView\u4ee5\u52a0\u8f7d\u548c\u663e\u793a\u60a8\u7684\u7f51\u9875\u5e94\u7528\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n

“`java<\/p>\n

import androidx.appcompat.app.AppCompatActivity;<\/p>\n

import android.os.Bundle;<\/p>\n

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

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

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

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

private WebView webView;<\/p>\n

@Override<\/p>\n

protected void onCreate(Bundle savedInstance<\/p>\n

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

State) {<\/p>\n

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

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

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

WebSettings webSettings = webView.getSettings();<\/p>\n

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

webView.setWebViewClient(new WebViewClient());<\/p>\n

webView.loadUrl(“https:\/\/example.com”);<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0c\u201chttps:\/\/example.com\u201d\u662f\u60a8\u7684\u7f51\u9875\u5e94\u7528\u7684URL\u3002\u786e\u4fddWebView\u8bbe\u7f6e\u4e2d\u542f\u7528\u4e86JavaScript\uff0c\u56e0\u4e3a\u8bb8\u591a\u73b0\u4ee3\u7f51\u9875\u5e94\u7528\u4f9d\u8d56\u4e8eJavaScript\u3002<\/p>\n

5. \u6d4b\u8bd5\u548c\u53d1\u5e03<\/p>\n

\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u8fd0\u884c\u8be5\u5e94\u7528\uff0c\u5e76\u5728\u6a21\u62df\u5668\u6216\u771f\u5b9e\u8bbe\u5907\u4e0a\u67e5\u770b\u60a8\u7684\u7f51\u9875\u5e94\u7528\u662f\u5426\u53ef\u4ee5\u6b63\u5e38\u5de5\u4f5c\u3002\u5982\u679c\u4e00\u5207\u987a\u5229\uff0c\u60a8\u53ef\u4ee5\u6309\u7167\u6b63\u5e38\u7684\u5b89\u5353\u5e94\u7528\u53d1\u5e03\u6d41\u7a0b\u5c06\u5176\u53d1\u5e03\u5230\u5e94\u7528\u5546\u5e97\u3002<\/p>\n

\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u5c06\u73b0\u6709\u7684\u7f51\u9875\u5e94\u7528\u8f6c\u5316\u4e3a\u5b89\u5353APP\u3002\u8fd9\u79cd\u65b9\u6cd5\u5bf9\u4e8e\u90a3\u4e9b\u8de8\u591a\u4e2a\u5e73\u53f0\u8fd0\u884c\u4e14\u9700\u8981\u51cf\u5c0f\u5f00\u53d1\u6210\u672c\u7684\u9879\u76ee\u975e\u5e38\u6709\u7528\u3002\u4f46\u8bf7\u6ce8\u610f\uff0c\u7531\u4e8eWebView\u6027\u80fd\u53ef\u80fd\u4f4e\u4e8e\u539f\u751f\u7ec4\u4ef6\uff0c\u6240\u4ee5\u590d\u6742\u7684\u5e94\u7528\u53ef\u80fd\u65e0\u6cd5\u63d0\u4f9b\u6700\u4f73\u7684\u7528\u6237\u4f53\u9a8c\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u8003\u8651\u5176\u4ed6\u6280\u672f\uff0c\u5982React Native\u3001Flutter\u7b49\uff0c\u4ee5\u5b9e\u73b0\u66f4\u63a5\u8fd1\u539f\u751f\u5e94\u7528\u7684\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u5b89\u5353\u7f51\u9875\u751f\u6210APP\u7684\u539f\u7406\u548c\u8be6\u7ec6\u4ecb\u7ecd\u3002\u73b0\u4ee3\u79fb\u52a8\u5e94\u7528\u5f00\u53d1\u9700\u8981\u5728\u591a\u4e2a\u5e73\u53f0\uff08\u5982\u5b89\u5353\u3001iOS\u7b49\uff09\u4e0a\u63d0\u4f9b\u76f8\u4f3c\u7684\u4f53\u9a8c\u3002\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u662f\u5c06\u73b0\u6709\u7684\u7f51\u9875\u5e94\u7528\u8f6c\u5316\u4e3a\u4e00\u4e2a\u53ef\u5728\u79fb\u52a8\u8bbe\u5907\u4e0a\u8fd0\u884c\u7684APP\uff0c\u8fd9<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[904,736,15187,149,15186],"topic":[],"class_list":["post-8855","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-904","tag-736","tag-app","tag-149","tag-app-"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/8855","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\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=8855"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/8855\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=8855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=8855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=8855"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=8855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}