Как встроить веб-просмотра в деятельности для отображения фрагментов HTML? - PullRequest
0 голосов
/ 28 июня 2011

все.Кто-нибудь даст мне подсказку или инструкции о том, как добавить веб-представление в иерархию представлений действия и позволить ему показывать фрагменты html?

Ответы [ 2 ]

0 голосов
/ 01 июля 2011

В папке 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>

А затем в своей деятельности:

WebView wv1 = (WebView)findViewById(R.id.web);
wv1.loadDataWithBaseURL(null, "HTML String", mimeType, encoding, null);
0 голосов
/ 28 июня 2011

создать 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>

в вашей активности

final String mimeType = "text/html";
final String encoding = "utf-8";
String nBody = "PUT YOUR HTML HERE" ;
WebView wv1 = (WebView)findViewById(R.id.wv2);
wv1.setBackgroundColor(Color.WHITE);
wv1.setInitialScale(65);
WebSettings webSettings1 = wv1.getSettings();
webSettings1.setUseWideViewPort(true);
webSettings1.setDefaultFontSize(12);
wv1.loadDataWithBaseURL(null, nBody, mimeType, encoding, null);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...