我有点不好意思发布这个,但我似乎无法弄清楚我哪里出错了。我看过每一个例子和每一个教程,一切对我来说都是正确的。这就是我正在做的事情。我有一个列表视图,当您单击一个项目时,它会将您带到一个 Web 视图,该视图显示一些与该列表条目关联的静态格式化文本。
我使用 TextView 完成了所有工作,但我希望能够对文本使用 HTML 格式,并认为 WebView 是可行的方法。现在它只是为了测试目的而显示一个通用链接,但是当 viewContent 意图启动时它只是进入黑屏。我可以回去选择另一个条目,它也只是显示黑屏。
我不确定您要查看什么代码,所以这里是 viewSection 类文件和 viewsection.xml 布局。
viewSection.java:
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class viewSection extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView wv;
setContentView(R.layout.viewsection);
wv = (WebView) findViewById(R.id.wv1);
wv.loadData("<a href='x'>Hello World! - 1</a>",
"text/html",
"utf-8");
}
}
viewsection.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<WebView android:id="@+id/wv1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
</LinearLayout>