0

我的 WebView 没有显示任何内容。它只是空的。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <WebView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

  <!--   <LinearLayout
        android:id="@+id/tableRow"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/buttonAccept"
            android:layout_width="0sp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/button_accept" />

        <Button
            android:id="@+id/buttonDeny"
            android:layout_width="0sp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/button_deny" />
    </LinearLayout> -->

</LinearLayout>

这是活动:

public class TermsOfUseDialogActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.terms_menu_dialog);

        WebView webview = (WebView) findViewById(R.id.webview);
//      WebView webview = new WebView(this);
//      setContentView(webview);

        String htmlCode = "<html><body>WebView Test<br /><br />New Line Test</body></html>";
        // webview.loadDataWithBaseURL(null, htmlCode, "text/html", "UTF-8", null);

//      webview.clearView();
        webview.loadData(htmlCode, "text/html", "UTF-8");
//      webview.reload();

        // webview.loadUrl("http://www.google.at");
    }
}

如您所见,我注释掉了一些代码。如果这些尝试有效,则没有,除了这部分......

WebView webview = new WebView(this);
setContentView(webview);

在这种情况下,我看到了内容,但我不能使用它,因为我也需要使用上面 XML 中显示的按钮。任何想法为什么这不显示任何内容?

(上网权限在AndroidManifest中设置)

4

1 回答 1

0

我找到了解决方案。布局不正确。使用以下布局,我有一个全屏 Web 视图,下面有 2 个按钮:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

  <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/buttonRow"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true">

        <Button
            android:id="@+id/buttonAccept"
            android:layout_width="0sp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/button_accept" />

        <Button
            android:id="@+id/buttonDeny"
            android:layout_width="0sp"
            android:layout_height="wrap_content"
            android:text="@string/button_deny"
            android:layout_weight="1" />
  </LinearLayout>

    <WebView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_above="@+id/buttonRow"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</RelativeLayout>
于 2013-01-20T07:20:11.093 回答