{"id":22330,"date":"2024-04-24T15:31:11","date_gmt":"2024-04-24T07:31:11","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=22330"},"modified":"2024-04-24T15:31:11","modified_gmt":"2024-04-24T07:31:11","slug":"%e7%bd%91%e9%a1%b5%e6%89%93%e5%8c%85%e6%88%90%e5%ae%89%e5%8d%93app%e6%93%8d%e4%bd%9c%e6%96%b9%e6%b3%95%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/22330\/","title":{"rendered":"\u7f51\u9875\u6253\u5305\u6210\u5b89\u5353app\u64cd\u4f5c\u65b9\u6cd5\u4ecb\u7ecd"},"content":{"rendered":"

\u5728\u79fb\u52a8\u5e94\u7528\u5f00\u53d1\u9886\u57df\u4e2d\uff0c\u6709\u4e00\u79cd\u53eb\u505a\u201cWeb\u5e94\u7528\u201d\u7684\u5f00\u53d1\u65b9\u5f0f\uff0c\u4e5f\u5c31\u662f\u4f7f\u7528\u73b0\u6709\u7684\u7f51\u9875\u6280\u672f\u6765\u5f00\u53d1\u79fb\u52a8\u5e94\u7528\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u52bf\u5728\u4e8e\uff0c\u5f00\u53d1\u8005\u53ea\u9700\u4f7f\u7528\u719f\u6089\u7684HTML\u3001CSS\u548cJavaScript\u6280\u672f\uff0c\u5c31\u53ef\u4ee5\u5c06\u4e00\u4e2a\u7f51\u9875\u6216Web\u5e94\u7528\u6253\u5305\u6210\u4e00\u4e2a\u5b89\u5353APP\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4e86\u89e3\u5982\u4f55\u5c06\u7f51\u9875\u6253\u5305\u6210\u5b89\u5353APP\u4ee5\u53ca\u8fd9\u80cc\u540e\u7684\u539f\u7406\u3002<\/p>\n

\u539f\u7406\u4ecb\u7ecd\uff1a<\/p>\n

1. WebView\u7ec4\u4ef6<\/p>\n

\u5b89\u5353\u63d0\u4f9b\u4e86\u4e00\u4e2a\u540d\u4e3aWebView\u7684\u7ec4\u4ef6\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u5728APP\u5185\u90e8\u5c55\u793a\u7f51\u9875\u5185\u5bb9\u3002\u4e8b\u5b9e\u4e0a\uff0cWebView\u662f\u6d4f\u89c8\u5668\u7684\u4e00\u90e8\u5206\uff0c\u4f46\u5b83\u662f\u4e0e\u6d4f\u89c8\u5668\u5206\u79bb\u7684\uff0c\u53ef\u4ee5\u76f4\u63a5\u5d4c\u5165\u5230\u5b89\u5353APP\u4e2d\u3002\u5f53\u4e00\u4e2a\u7f51\u9875\u88ab\u6253\u5305\u6210APP\u65f6\uff0c\u5b9e\u9645\u4e0a\u662f\u521b\u5efa\u4e86\u4e00\u4e2a\u5185\u7f6eWebView\u7684\u5b89\u5353APP\uff0c\u7136\u540e\u8ba9WebView\u52a0\u8f7d\u5e76\u663e\u793a\u8be5\u7f51\u9875\u3002<\/p>\n

2. Web\u5bb9\u5668<\/p>\n

\u8981\u5c06\u7f51\u9875\u6253\u5305\u6210\u5b89\u5353APP\uff0c\u5f00\u53d1\u8005\u8fd8\u9700\u8981\u4e00\u4e2a\u540d\u4e3a\u201cWeb\u5bb9\u5668\u201d\u7684\u5e94\u7528\u7a0b\u5e8f\u3002Web\u5bb9\u5668\u7684\u4efb\u52a1\u662f\u626e\u6f14\u4e2d\u95f4\u4eba\u7684\u89d2\u8272\uff0c\u534f\u52a9WebView\u663e\u793a\u7f51\u9875\u5185\u5bb9\uff0c\u540c\u65f6\u5904\u7406\u5b89\u5353\u4e0e\u7f51\u9875\u95f4\u7684\u4ea4\u4e92\u3002\u4f8b\u5982\uff0c\u5f53\u7528\u6237\u5728APP\u5185\u70b9\u51fb\u4e00\u4e2a\u6309\u94ae\u65f6\uff0cWeb\u5bb9\u5668\u53ef\u4ee5\u5c06\u4e8b\u4ef6\u4f20\u9012\u7ed9WebView\uff0c\u5e76\u6267\u884c\u76f8\u5e94\u7684JavaScript\u4ee3\u7801\u3002<\/p>\n

\u8be6\u7ec6\u4ecb\u7ecd\uff1a<\/p>\n

\u4e0b\u9762\u6211\u4eec\u5c06\u901a\u8fc7\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff0c\u4ece\u96f6\u5f00\u59cb\u5b66\u4e60\u5982\u4f55\u5c06\u4e00\u4e2a\u7f51\u9875\u6253\u5305\u6210\u5b89\u5353APP\u3002<\/p>\n

1. \u51c6\u5907\u5de5\u4f5c<\/p>\n

\u9996\u5148\uff0c\u786e\u4fdd\u60a8\u5df2\u7ecf\u62e5\u6709\u4ee5\u4e0b\u5de5\u5177\u548c\u8d44\u6e90\uff1a<\/p>\n

– Android Studio\uff1a\u5b89\u5353\u7684\u5b98\u65b9\u5f00\u53d1\u5de5\u5177<\/p>\n

– \u7f51\u9875\u6e90\u4ee3\u7801\uff1aHTML\u3001CSS\u548cJavaScript\u6587\u4ef6<\/p>\n

– \u4e92\u8054\u7f51\u8fde\u63a5<\/p>\n

2. \u521b\u5efa\u65b0\u7684\u5b89\u5353\u9879\u76ee<\/p>\n

\u5728Android Studio\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b89\u5353\u9879\u76ee\u5e76\u4e3a\u5176\u547d\u540d\u3002\u9009\u62e9\u201cEmpty Activity\u201d\u4f5c\u4e3a\u9879\u76ee\u6a21\u677f\uff0c\u7136\u540e\u70b9\u51fb\u201cFinish\u201d\u3002<\/p>\n

3. \u6dfb\u52a0WebViewapp\u5c01\u88c5\u5e73\u53f0\u8f7b\u6253\u5305<\/a>\u7ec4\u4ef6<\/p>\n

\u5728\u9879\u76ee\u4e2d\u627e\u5230\u201cactivity_main.xml\u201d\u6587\u4ef6\uff0c\u5b83\u4f4d\u4e8e\u201cres\/layout\u201d\u76ee\u5f55\u4e0b\u3002\u7528\u4ee5\u4e0b\u4ee3\u7801\u66ff\u6362\u5176\u5185\u5bb9\uff1a<\/p>\n

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

xmlns:app=”http:\/\/schemas.android.com\/apk\/res-auto”<\/p>\n

xmlns:tools=”http:\/\/schemas.android.com\/tools”<\/p>\n

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

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

tools:context=”.MainActivity”><\/p>\n<\/p>\n

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

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

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

app:layout_constraintBottom_toBottomOf=”parent”<\/p>\n

app:layout_constraintEnd_toEndOf=”parent”<\/p>\n

app:layout_constraintStart_th5\u5f00\u53d1app<\/a>oStartOf=”parent”<\/p>\n

app:layout_constraintTop_toTopOf=”<\/p>\n

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

parent” \/><\/p>\n

“`<\/p>\n

4. \u521d\u59cb\u5316WebView<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u521d\u59cb\u5316WebView\u3002\u5728MainActivity\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n

“`java<\/p>\n

…<\/p>\n

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

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

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

WebView myWebView;<\/p>\n

@Override<\/p>\n

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

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

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

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

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

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

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

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

}<\/p>\n

}<\/p>\n

“`<\/p>\n

5. \u5c06\u7f51\u9875\u6587\u4ef6\u6dfb\u52a0\u5230\u9879\u76ee<\/p>\n

\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cwww\u201d\u7684\u6587\u4ef6\u5939\uff0c\u5c06\u60a8\u7684HTML\u3001CSS\u548cJavaScript\u6587\u4ef6\u653e\u5165\u5176\u4e2d\u3002\u7136\u540e\u5c06\u6574\u4e2a\u6587\u4ef6\u5939\u590d\u5236\u5230\u201capp\/src\/main\/assets\u201d\u76ee\u5f55\u4e0b\u3002<\/p>\n

6. \u7f16\u8bd1\u548c\u8fd0\u884c<\/p>\n

\u6700\u540e\uff0c\u70b9\u51fbAndroid Studio\u4e2d\u7684<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u79fb\u52a8\u5e94\u7528\u5f00\u53d1\u9886\u57df\u4e2d\uff0c\u6709\u4e00\u79cd\u53eb\u505a\u201cWeb\u5e94\u7528\u201d\u7684\u5f00\u53d1\u65b9\u5f0f\uff0c\u4e5f\u5c31\u662f\u4f7f\u7528\u73b0\u6709\u7684\u7f51\u9875\u6280\u672f\u6765\u5f00\u53d1\u79fb\u52a8\u5e94\u7528\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u52bf\u5728\u4e8e\uff0c\u5f00\u53d1\u8005\u53ea\u9700\u4f7f\u7528\u719f\u6089\u7684HTML\u3001CSS\u548cJavaScript\u6280\u672f\uff0c\u5c31\u53ef\u4ee5\u5c06\u4e00\u4e2a\u7f51\u9875<\/p>\n","protected":false},"author":25,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[3029,16,7812,149,22137],"topic":[],"class_list":["post-22330","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-3029","tag-16","tag-app","tag-149","tag-cmsapp"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/22330","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\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=22330"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/22330\/revisions"}],"predecessor-version":[{"id":22364,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/22330\/revisions\/22364"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=22330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=22330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=22330"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=22330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}