您的位置:首页 > 移动开发

Android 显示 WebView ,加载URL 时,向webview的 header 里面传递参数

2015-11-19 16:02 537 查看
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 ) ;
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: