zoukankan      html  css  js  c++  java
  • webview progress bar

    1.

    package tuo.test.activity;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.view.Window;
    import android.webkit.JsResult;
    import android.webkit.WebChromeClient;
    import android.webkit.WebView;
    import android.widget.Toast;
    
    public class Browser extends Activity {
    	private static final String TAG = "Browser";
    	private WebView webView;
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		// TODO Auto-generated method stub
    		super.onCreate(savedInstanceState);
    		this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
    		this.getWindow().setFeatureInt(Window.FEATURE_PROGRESS,
    				Window.PROGRESS_VISIBILITY_ON);
    		setContentView(R.layout.browser);
    		loadHtml();
    	}
    	@Override
    	public boolean onKeyDown(int keyCode, KeyEvent event) {
    		// TODO Auto-generated method stub
    		if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
    			webView.goBack();
    			return true;
    		}
    		return super.onKeyDown(keyCode, event);
    	}
    
    	private void loadHtml() {
    		String action = getIntent().getStringExtra("action");
    		String html = "file:///android_asset/html/person.html?action=" + action;
    		webView = (WebView) findViewById(R.id.web_view);
    		webView.getSettings().setJavaScriptEnabled(true);
    		webView.addJavascriptInterface(this, "android");
    		webView.setWebChromeClient(new WebChromeClient() {
    			@Override
    			public boolean onJsAlert(WebView view, String url, String message,
    					JsResult result) {
    				// TODO Auto-generated method stub
    				Toast.makeText(Browser.this, message, 3000).show();
    				result.confirm();
    				return true; // I handled it
    			}
    			
    			public void onProgressChanged(WebView view, int newProgress) {
    				// TODO Auto-generated method stub
    				// super.onProgressChanged(view, newProgress);
    				setTitle("loading...");
    				setProgress(newProgress * 100);
    				if (newProgress == 100) {
    					setTitle("");
    				}
    			}
    		});
    		webView.loadUrl(html);
    	}
    	
    	public  String  getHISAccount() {
    		return "00000";
    	}
    
    	
    }
    
  • 相关阅读:
    如何在CentOS 7中安装最新Git(源码安装)
    centos7安装Lua
    syslog-ng 学习
    syslog-ng内容讲解
    java框架篇---spring IOC 实现原理
    java 过滤器filter使用案例
    jsp-TagLib标签库
    阿里服务器+Centos7.4+Tomcat+JDK部署
    IntelliJ IDEA上创建maven Spring MVC项目
    ServiceStack.Redis之IRedisClient
  • 原文地址:https://www.cnblogs.com/tuolin/p/2181503.html
Copyright © 2011-2022 走看看