展会信息港展会大全

如何使用WebView?如何实现程序内置浏览器查看网页?
来源:互联网   发布日期:2016-01-14 11:35:10   浏览:2378次  

导读:RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:tools=http://schemas.android.com/tools android:layout_width=match_parent android:layout_height=match_parent tools:context=com.pku.ipku.ui.util.WebViewActivity We...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="com.pku.ipku.ui.util.WebViewActivity">

<WebView

android:id="@+id/webview"

android:layout_width="fill_parent"

android:layout_height="match_parent"

android:background="@color/white" />

</RelativeLayout>

public class WebViewActivity extends Activity {

private WebView webView;

//webview要访问的地址

private String url;

@Override

protected void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_web_view);

url = getIntent().getStringExtra("url");

super.onCreate(savedInstanceState);

webView = (WebView) findViewById(R.id.webview);

setWebViewContent(webView, url);

}

private void setWebViewContent(WebView webView, String url) {

webView.getSettings().setJavaScriptEnabled(true);

webView.getSettings().setSupportZoom(true);

webView.getSettings().setBuiltInZoomControls(true);

webView.getSettings().setDefaultFontSize(15);

webView.setInitialScale(100);

webView.loadUrl(url);

webView.setWebViewClient(new WebViewClient() {

@Override

public void onReceivedSslError(WebView view, SslErrorHandler handler,

SslError error) {

handler.proceed();

}

});

}

}

赞助本站

人工智能实验室

相关热词: android开发 android教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港