80,330
社区成员
发帖
与我相关
我的任务
分享
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebViewDemoActivity extends Activity {
/** Called when the activity is first created. */
private WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
LinearLayout ll = new LinearLayout(this);
mWebView = new WebView(this);
//mWebView = (WebView) findViewById(R.id.webview);
String html = "<img src='http://www.baidu.com/img/baidu_sylogo1.gif'>";
mWebView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
ll.addView(mWebView);
TextView tv = new TextView(this);
tv.setText("hahaha");
ll.addView(tv);
setContentView(ll);
*/
setContentView(R.layout.webdemo);
mWebView = (WebView) findViewById(R.id.webview);
String html = "<img src='http://www.baidu.com/img/baidu_sylogo1.gif'>";
mWebView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>