gpt4 book ai didi

android - 如何在不使用浏览器的情况下在我们的 Android 应用程序中显示网页内容

转载 作者:行者123 更新时间:2023-11-30 01:35:01 24 4
gpt4 key购买 nike

在这里,我正在开发一个 Android 应用程序和网页。我需要在不使用浏览器的情况下在我的 android Activity 中显示网络内容。

我正在使用 WebView 来满足这个要求。但问题是,如果我单击它在浏览器中打开的按钮。

在这里,我必须在我的 Android 应用程序中将该页面显示为新 Activity 。

这是我针对此问题尝试过的代码。

WebView .xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:ignore="MergeRootFrame">

<WebView
android:id="@+id/activity_tab_host_webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>

这是我的Admissionactivity,需要显示网页内容

    public class AdmissionActivity extends Activity {

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view);

webView = (WebView) findViewById(R.id.activity_tab_host_webview);
webView.loadUrl("http://www.google.com");
}
}

这是点击按钮的代码

 @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_college_listview);
intro = (TextView) findViewById(R.id.intro_button);
intro.setText("Introduction");
intro.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
Intent admAct = new Intent(getApplicationContext(), AdmissionActivity.class);
// Clears History of Activity
admAct.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(admAct);


}

});
}

最佳答案

只需实现网络客户端并将其设置在loadUrl 之前。最简单的方法是:

myWebView.setWebViewClient(new WebViewClient());

关于android - 如何在不使用浏览器的情况下在我们的 Android 应用程序中显示网页内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35217912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com