zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    webpack实现开发、测试、生产等环境的打包切换
    Python报错
    WGAN将数值限制在一定范围内 Python代码 tf.clip_by_value(p, -0.01, 0.01))
    cmd 进入指定文件夹
    Wasserstein 距离
    MSE(均方误差)、RMSE (均方根误差)、MAE (平均绝对误差)
    inf
    plt画log图
    KL散度与JS散度
    安装指定版本的第三方包
  • 原文地址:https://www.cnblogs.com/zhaoyanjun/p/4977929.html
Copyright © 2011-2022 走看看