Android webView如何输出自定义网页
更新时间:2020年09月23日 10:02:41 作者:手撕高达的村长
这篇文章主要介绍了Android webView如何输出自定义网页,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
这次来使用webview输出网页型数据。因为这样的数据好使用富文本编辑器,有各种各样的拓展。
上代码:
package controller.hzl.com.testcall; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private WebView webView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String webs = "\"<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>hello tomcat</title>\n" + "</head>\n" + "<body>\n" + " <h1>1</h1>\n" + " <p>2</p>" + "tel:13800138000" + "</body>\n" + "</html>\"" ; webView = (WebView) findViewById( R.id.webview ); //webview webView.loadDataWithBaseURL( null, webs , "text/html", "UTF-8", null ) ; } }
页面代码:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context=".MainActivity"> <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent"> </WebView> </RelativeLayout>
这里提示一点,如果想要拿网页进行显示的话,需要加一行代码,不然显示不了。
</application> <uses-permission android:name="android.permission.INTERNET" />
代码完毕,放结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
Android开发中RecyclerView组件使用的一些进阶技讲解
RecyclerView是Android 5.0以来新加入的一个组件,基本上全面优于ListView,这里我们将来关注Android开发中RecyclerView组件使用的一些进阶技讲解:2016-06-06Android自定义view实现左滑删除的RecyclerView详解
RecyclerView是Android一个更强大的控件,其不仅可以实现和ListView同样的效果,还有优化了ListView中的各种不足。其可以实现数据纵向滚动,也可以实现横向滚动(ListView做不到横向滚动)。接下来讲解RecyclerView的用法2022-11-11Android Studio连接SQLite数据库的登录注册实现
这篇文章主要介绍了Android Studio连接SQLite数据库的登录注册实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-06-06
最新评论