public class MainActivity extends Activity {
private WebView webview;
//private EditText url;
private String url="http://www.zhangwenlong.cn/?post=275";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview=(WebView) findViewById(R.id.webview);
webview.setWebViewClient(new webViewClient());
Button button=(Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
webview.goBack();//后退
// webview.goForward();//前进
// webview.reload(); //刷新
}
settings.setBuiltInZoomControls(true); // 显示放大缩小 controler
settings.setSupportZoom(true); // 可以缩放
webview.loadUrl(url);
webview.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
// TODO Auto-generated method stub
if(arg2.getAction()==KeyEvent.ACTION_DOWN)
{
if(arg1==KeyEvent.KEYCODE_BACK&&webview.canGoBack())
{
webview.goBack();//后退
return true;
}
}
return false;
}
});
}
//点击超练接 跳转
class webViewClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
}
private WebView webview;
//private EditText url;
private String url="http://www.zhangwenlong.cn/?post=275";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview=(WebView) findViewById(R.id.webview);
webview.setWebViewClient(new webViewClient());
Button button=(Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
webview.goBack();//后退
// webview.goForward();//前进
// webview.reload(); //刷新
}
});
settings.setBuiltInZoomControls(true); // 显示放大缩小 controler
settings.setSupportZoom(true); // 可以缩放
webview.loadUrl(url);
webview.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
// TODO Auto-generated method stub
if(arg2.getAction()==KeyEvent.ACTION_DOWN)
{
if(arg1==KeyEvent.KEYCODE_BACK&&webview.canGoBack())
{
webview.goBack();//后退
return true;
}
}
return false;
}
});
}
//点击超练接 跳转
class webViewClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
}
}
QQ群:247394475
关注微信公众号实时获取新内容