Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在活动中嵌入webview以显示html片段?_Android_Webview - Fatal编程技术网

Android 如何在活动中嵌入webview以显示html片段?

Android 如何在活动中嵌入webview以显示html片段?,android,webview,Android,Webview,全部。有人能给我一些关于如何将webview添加到活动视图层次结构并让它显示html的线索或说明吗?在布局文件夹中创建xml <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_w

全部。有人能给我一些关于如何将webview添加到活动视图层次结构并让它显示html的线索或说明吗?

在布局文件夹中创建xml

<?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/white">

        <WebView android:id="@+id/wv1"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:background="@color/white" />

        <WebView android:id="@+id/wv2"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:background="@color/white"/>

    </FrameLayout>

在res文件夹中创建一个XML文件,在res文件夹中声明您的WebView

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@color/white">
    <WebView android:id="@+id/web" android:layout_height="fill_parent"
        android:layout_width="fill_parent" android:background="@color/white" />
</FrameLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@color/white">
    <WebView android:id="@+id/web" android:layout_height="fill_parent"
        android:layout_width="fill_parent" android:background="@color/white" />
</FrameLayout>
WebView wv1 = (WebView)findViewById(R.id.web);
wv1.loadDataWithBaseURL(null, "HTML String", mimeType, encoding, null);