1. 加载 html 代码

布局文件中引入 WebView 控件。

  1. <WebView android:id="@+id/book_content"
  2. android:layout_height="match_parent"
  3. android:layout_width="match_parent"/>

活动文件中设置加载 html。

  1. WebView content = findViewById(R.id.book_content);
  2. content.loadDataWithBaseURL(null, "<h1>hello world!</h1>",
  3. "text/html", "utf-8", null);