实现在android客户端使用Webview;
java xml布局;
<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=".MainActivity" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true" />
</RelativeLayout>
java源代码:
<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=".MainActivity" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true" />
</RelativeLayout>
注意: 需要添加权限----》 <uses-permission android:name="android.permission.INTERNET"/>
package com.example.androidwebview;
import android.os.Bundle;
import android.app.Activity;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
private WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.activity_main);
webview=(WebView)findViewById(R.id.webView1);
//应用里面显示浏览器;
webview.setWebViewClient(new WebViewClient());
//要求网页能适应不同的屏幕;
//给手机用wap;给电脑用www;开头;
webview.loadUrl("http://write.blog.youkuaiyun.com/postlist");
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.example.androidwebview;
import android.os.Bundle;
import android.app.Activity;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
private WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
setContentView(R.layout.activity_main);
webview=(WebView)findViewById(R.id.webView1);
//应用里面显示浏览器;
webview.setWebViewClient(new WebViewClient());
//要求网页能适应不同的屏幕;
//给手机用wap;给电脑用www;开头;
webview.loadUrl("http://write.blog.youkuaiyun.com/postlist");
} catch (Exception e) {
e.printStackTrace();
}
}
}
本文介绍如何在Android应用中集成WebView组件来加载并显示网页。通过XML布局文件设置WebView的属性,并在Java代码中加载指定URL,实现网页内容的展示。
4262

被折叠的 条评论
为什么被折叠?



