webview显示问题,在模拟器什么都不显示

robotsz 2012-10-11 05:20:11

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);

}
}




webdemo.xml


<?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>


显示效果



想要显示一段html语句在WebView里面,但是始终没有任何显示,哪里出错了吗?
...全文
208 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

80,330

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧