切换Fresco框架
This commit is contained in:
77
app/src/main/java/com/gh/gamecenter/WebActivity.java
Normal file
77
app/src/main/java/com/gh/gamecenter/WebActivity.java
Normal file
@ -0,0 +1,77 @@
|
||||
package com.gh.gamecenter;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.gh.base.BaseActivity;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/10/18.
|
||||
*/
|
||||
public class WebActivity extends BaseActivity {
|
||||
private WebView mWebView;
|
||||
private ProgressBar mProgressBar;
|
||||
|
||||
private String webUrl;
|
||||
private String webTitle;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle extras = getIntent().getExtras();
|
||||
webUrl = extras.getString("url");
|
||||
webTitle = extras.getString("gameName");
|
||||
|
||||
View contentView = View.inflate(this, R.layout.activity_web, null);
|
||||
init(contentView, webTitle);
|
||||
|
||||
mWebView = (WebView) findViewById(R.id.news_webview);
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.web_progressbar);
|
||||
|
||||
mWebView.loadUrl(webUrl);
|
||||
|
||||
WebSettings settings = mWebView.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
|
||||
//用webview打开url
|
||||
mWebView.setWebViewClient(new WebViewClient(){
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
view.loadUrl(url);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
//设置加载进度条
|
||||
mWebView.setWebChromeClient(new WebChromeClient(){
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
mProgressBar.setProgress(newProgress);
|
||||
if (newProgress == 100){
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
} else {
|
||||
if (mProgressBar.getVisibility() == View.GONE) {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
|
||||
mWebView.goBack();// 返回前一个页面
|
||||
return true;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user