是否可以在Android原生应用程序中使用HTML?

Bre*_*sen 2 html java html5 android native

我正在开发android原生应用程序.我正在使用图像和文字.所以,我决定在布局中使用HTML.但我不知道是否有可能,如果可能的话.

问候

Hal*_*oum 7

您可以WebView在布局中渲染.WebView例如,这可以指向远程或本地资源,例如HTML/JS/CSS文件.

以下是如何在布局中声明Webview:

<WebView
    android:id="@+id/mywebview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="visible" />
Run Code Online (Sandbox Code Playgroud)

并在代码中使用/初始化它:

/* Retrieve your webview and manipulate it using a reference to
  the object created in your XML */
WebView webview = (WebView) this.findViewById(R.id.mywebview);
/* If you would like to use Javascript in your view */
webview.getSettings().setJavaScriptEnabled(true);
/* Load the URL to the resource you want to load in your view */
webview.loadUrl("http://hostname/...");
Run Code Online (Sandbox Code Playgroud)