WebView 显示黑屏 [英] WebView displays black screen

查看:48
本文介绍了WebView 显示黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点不好意思张贴这个,但我似乎无法弄清楚我哪里出错了.我看过每一个例子和每一个教程,一切对我来说都是正确的.这就是我正在做的.一世有一个列表视图,当你点击一个项目时,它会带你到一个显示一些与之相关的静态格式化文本的 WebView列表条目.

I'm a little embarrassed to post this but I can't seem to figure out where I'm going wrong. I've looked at every example and every tutorial and everything looks right to me. Here's what I'm doing. I have a listview that when you click on an item it will take you to a WebView that displays some static formatted text associated with that list entry.

我已经使用 TextView 完成了所有工作,但我希望能够使用文本的 HTML 格式并认为 WebView 是走.现在它只是应该显示一个通用链接测试目的,但是当 viewContent 意图开始时,它就会消失到黑屏.我可以回去选择另一个条目,它也只显示黑屏.

I had it all working with a TextView but I wanted to be able to use HTML formatting for the text and figured the WebView was the way to go. Right now it is just supposed to display a generic link for testing purposes but when the viewContent intent starts it just goes to a black screen. I can go back and pick another entry and it also just shows the black screen.

我不确定你想看什么代码,所以这里是viewSection 类文件和 viewsection.xml 布局.

I'm not sure what code you are going to want to see so here's the viewSection class file and the viewsection.xml layout.

viewSection.java:

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:

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>

推荐答案

您可能希望将 WebView 上的 android:layout_height 设置为 fill_parent.我不确定 WebView 是否支持 wrap_content.

You probably want to set android:layout_height on the WebView to fill_parent. I'm not sure if WebView supports wrap_content.

EDIT:您还需要将 LinearLayout 的宽度和高度设置为 fill_parent.

EDIT: You'll want to set the LinearLayout width and height to fill_parent as well.

此外,如果您使用非常轻的 HTML 样式,您仍然可以使用 TextView;API Demos 示例应用中有关于如何执行此操作的示例(即 StyledText.java链接.java).

Also, if you're using very light HTML styling, you can still use a TextView; there are samples in the API Demos sample app on how to do this (i.e. StyledText.java and Link.java).

这篇关于WebView 显示黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆