app\u7a0b\u5e8f\u5f00\u53d1\u591a\u5c11\u94b1<\/a>\u79f0\u548c\u5305\u540d\uff0c\u5e76\u9009\u62e9\u8981\u652f\u6301\u7684\u6700\u4f4e\u7cfb\u7edf\u7248\u672c\u3002<\/p>\n\u6b65\u9aa43\uff1a\u6dfb\u52a0Webview\u7ec4\u4ef6<\/p>\n
\u5728\u9879\u76ee\u7684\u5e03\u5c40\u6587\u4ef6(activity_main.xml)\u4e2d\uff0c\u6dfb\u52a0Webview\u7ec4\u4ef6\u4ee3\u7801\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
\u6b65\u9aa44\uff1a\u6dfb\u52a0\u7f51\u7edc\u8bbf\u95ee\u6743\u9650<\/p>\n
\u5728AndroidManifest.xml\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u6743\u9650\u8bf7\u6c42\u4ee3\u7801\uff0c\u4ee5\u5141\u8bb8App\u8bbf\u95ee\u7f51\u7edc\uff1a<\/p>\n
“`xml<\/p>\n<\/p>\n
“`<\/p>\n
\u6b65\u9aa45\uff1a\u52a0\u8f7d\u7f51\u9875\u5230Webview<\/p>\n
\u5728MainActivity.java\u6587\u4ef6\u4e2d\uff0c\u83b7\u53d6Webview\u7ec4\u4ef6\uff0c\u5e76\u8bbe\u7f6e\u5176\u5c5e\u6027\u4e0e\u521d\u59cb\u5316\u3002\u63a5\u7740\uff0c\u52a0\u8f7d\u9700\u8981\u6253\u5305\u7684\u7f51\u5740\uff0c\u5e76\u5728Webview\u4e2d\u5c55\u793a\u7f51\u9875\u5185\u5bb9\uff1a<\/p>\n
“`java<\/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 savedInstanceState) {<\/p>\n
super.onCreate(savedInstanceState);<\/p>\n
setContentView(R.layout.activity_main);<\/p>\n
webView = findViewById(R.id.webview);<\/p>\n
initWebView();<\/p>\n
webView.loadUrl(“https:\/\/www.example.com”);<\/p>\n
}<\/p>\n
private void initWebView() {<\/p>\n
WebSettings webSettings = webView.getSettings();<\/p>\n
webSettings.setJavaScriptEnabled(true);<\/p>\n
webSettings.setDomStorageEnabled(true);<\/p>\n
webSettings.setLoadWithOverviewMode(true);<\/p>\n
webSettings.setUseWideViewPort(true);<\/p>\n
webView.setWebViewClient(new WebViewClient());<\/p>\n
}<\/p>\n
@Override<\/p>\n
public void onBackPressed() {<\/p>\n
if (webView.canGoBack()) {<\/p>\n
\n
<\/figure>\n<\/p>\n webView.goBack();<\/p>\n
} else {<\/p>\n
super.onBackPressed();<\/p>\n
}<\/p>\n
}<\/p>\n
}<\/p>\n
“`<\/p>\n
\u6b65\u9aa46\uff1a\u6d4b\u8bd5\u8c03\u8bd5\u4e0e\u53d1\u5e03<\/p>\n
\u81f3\u6b64\uff0c\u5df2\u7ecf\u5b8c\u6210\u4e86\u7f51\u9875\u6253\u5305\u6210\u5b89\u5353App\u7684\u6838\u5fc3\u64cd\u4f5c\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u8fd0\u884c\u9879\u76ee\uff0c\u6d4b\u8bd5\u8c03\u8bd5\u81ea\u5df1\u7684App\u3002\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u5373\u53ef\u751f\u6210APK\u6587\u4ef6\u5e76\u53d1\u5e03\u5230\u5e94\u7528\u5e02\u573a\u3002<\/p>\n
\u603b\u7ed3\uff1a<\/p>\n
\u7f51\u9875\u6253\u5305\u6210\u5b89\u5353App\u662f\u4e00\u79cd\u5177\u6709\u5b9e\u7528\u6027\u7684\u6280\u672f\u65b9\u6848\uff0c\u80fd\u591f\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u5f00\u53d1\u51fa\u8de8\u5e73\u53f0\u5e94\u7528\uff0c<\/p>\n","protected":false},"excerpt":{"rendered":"
\u7f51\u9875\u6253\u5305\u6210\u5b89\u5353APP\uff08\u539f\u7406\u4e0e\u8be6\u7ec6\u4ecb\u7ecd\uff09\u5728\u4e92\u8054\u7f51\u4e16\u754c\u4e2d\uff0c\u7f51\u7ad9\u548c\u624b\u673aApp\u5206\u522b\u662f\u4e24\u79cd\u975e\u5e38\u6d41\u884c\u7684\u5e94\u7528\u5f62\u5f0f\u3002\u5982\u4eca\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u5f00\u53d1\u8005\u5c1d\u8bd5\u5c06\u7f51\u9875\u8f6c\u6362\u4e3a\u5b89\u5353APP\uff0c\u4ee5\u5b9e\u73b0\u591a\u5e73\u53f0\u540c\u6b65\u66f4\u65b0\uff0c\u8282\u7ea6\u65f6\u95f4\u548c\u8d44\u6e90\u3002\u4e3a\u4e86\u5e2e\u52a9\u5f00<\/p>\n","protected":false},"author":23,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15841,16195,797,736,149],"topic":[],"class_list":["post-24501","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-15841","tag-app","tag-797","tag-736","tag-149"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/24501","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\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=24501"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/24501\/revisions"}],"predecessor-version":[{"id":24576,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/24501\/revisions\/24576"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=24501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=24501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=24501"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=24501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}