Android 显示 WebView ,加载URL 时,向webview的 header 里面传递参数
1、主要布局
<?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>
2、代码实现
1 package com.webview.demo; 2 3 import android.os.Bundle; 4 import android.support.v7.app.AppCompatActivity; 5 import android.webkit.WebView; 6 7 import java.util.HashMap; 8 import java.util.Map; 9 10 public class MainActivity extends AppCompatActivity { 11 12 private WebView webView ; 13 14 private String webViewHeaderKey = "tokenId" ; 15 private String webViewHeaderValue = "562142" ; 16 17 private String url = "" ; 18 19 @Override 20 protected void onCreate(Bundle savedInstanceState) { 21 super.onCreate(savedInstanceState); 22 setContentView(R.layout.activity_main); 23 24 webView = (WebView) findViewById( R.id.webview ); 25 26 27 if ( webViewHeaderValue != "" ){ 28 Map<String, String > map = new HashMap<String, String>() ; 29 map.put( webViewHeaderKey , webViewHeaderValue ) ; 30 31 webView.loadUrl( url , map ) ; 32 }else { 33 webView.loadUrl( url ) ; 34 } 35 36 } 37 }
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
webView 显示一段 html 代码
1、布局文件 <?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> 2、代码 package com.webview.d...
- 下一篇
android studio 使用SVN 锁定文件,防止别人修改(基于Android studio 1.4 )
首先假设开发 A , 和 开发 B , 在使用 SVN 进行项目管理。那么A如何才能 某个锁定文件,防止B修改。 1、第一步,给这个文件加锁 完成这一步,则这个文件就别锁定了。 2、第二步,假如B去把这个文件修改了几行代码,然后 commit 开发B commit 失败,因为A已经锁定了文件 3、第三步,开发A 解除文件锁定 4、第四步,A把文件解锁后,这个开发 B 就可以正常的commit 了
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- SpringBoot2整合Redis,开启缓存,提高访问速度
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- Hadoop3单机部署,实现最简伪集群
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- SpringBoot2更换Tomcat为Jetty,小型站点的福音
- CentOS8编译安装MySQL8.0.19