0

我的应用程序中的 webview 没有显示。我去互联网寻找答案,但我什么也没找到,只是有关如何使用控件的教程。我正在尝试加载一个 html 文件,但它没有显示。

我在清单中添加了用户权限“Internet”。

这是我的布局:

<TableLayout 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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:visibility="visible" >

        <WebView
            android:id="@+id/wvInfo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </TableRow>
</TableLayout>

我的资产文件夹中有一个文件“filename.html”。

以下代码在 onCreate 中:

  WebView wvinfo = (WebView) findViewById(R.id.wvInfo);
  wvinfo.loadUrl("file:///android_asset/filename.html");

当我在手机上加载程序时,什么也没有出现。我还尝试加载一个网址“ http://www.google.com ”,但仍然没有显示。我难住了。有任何想法吗?

4

3 回答 3

1

在您的布局文件中尝试以下代码

<TableLayout 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"
    >



        <WebView
            android:id="@+id/wvInfo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

</TableLayout>
于 2013-05-16T06:05:16.417 回答
0

我的猜测是你还没有 setContent 里面的布局onCreate()

试试这样...

setContentView(R.layout.webview_layout);

于 2013-05-16T05:54:34.513 回答
0

为什么要为 Web 视图使用表格布局?而是使用线性或相对布局。

尝试添加这个

WebView wvinfo = (WebView) findViewById(R.id.wvInfo);
        wvinfo .getSettings().setJavaScriptEnabled(true);        
       wvinfo.loadUrl("file:///android_asset/filename.html");

让我知道它是否有效。

于 2013-05-16T05:55:44.390 回答