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、代码实现

 package com.webview.demo;

 import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebView; import java.util.HashMap;
import java.util.Map; public class MainActivity extends AppCompatActivity { private WebView webView ; private String webViewHeaderKey = "tokenId" ;
private String webViewHeaderValue = "562142" ; private String url = "" ; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); webView = (WebView) findViewById( R.id.webview ); if ( webViewHeaderValue != "" ){
Map<String, String > map = new HashMap<String, String>() ;
map.put( webViewHeaderKey , webViewHeaderValue ) ; webView.loadUrl( url , map ) ;
}else {
webView.loadUrl( url ) ;
} }
}
上一篇:Linux分区方案 (转)


下一篇:Swing-setOpaque()用法-入门