展会信息港展会大全

webview简单使用 android开发源代码
来源:互联网   发布日期:2015-10-02 21:23:52   浏览:3079次  

导读:package com.travel_lover;import android.os.Bundle;import android.annotation.SuppressLint;import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInterface;imp......

package com.travel_lover;

import android.os.Bundle;

import android.annotation.SuppressLint;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.view.KeyEvent;

import android.view.Menu;

import android.view.MenuItem;

import android.view.Window;

import android.view.WindowManager;

import android.webkit.WebChromeClient;

import android.webkit.WebView;

import android.webkit.WebViewClient;

import android.support.v4.app.NavUtils;

public class WebActivity extends Activity {

WebView mywebview;

@SuppressLint("SetJavaScriptEnabled")

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_PROGRESS);

setContentView(R.layout.activity_web);

mywebview=(WebView)findViewById(R.id.webView1);

mywebview.getSettings().setJavaScriptEnabled(true);

//设置进度条

mywebview.setWebChromeClient(new WebChromeClient() {

public void onProgressChanged(WebView view, int progress) {

WebActivity.this.setProgress(progress * 100);

}

});

mywebview.loadUrl("http://tuan.baidu.com/");

//使用自己的Browser,不调用系统自带的

mywebview.setWebViewClient(new WebViewClient(){

public boolean shouldOverrideUrlLoading(WebView view, String url) {

view.loadUrl(url);

return true;

}

});

}

public boolean onKeyDown(int keyCode,KeyEvent event){

if ((keyCode == KeyEvent.KEYCODE_BACK) && mywebview.canGoBack()){

mywebview.goBack();

return true;

}

if (keyCode == KeyEvent.KEYCODE_BACK) {

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setMessage("离开团购信息?")

.setCancelable(false)

.setPositiveButton("确定",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,

int id) {

WebActivity.this.finish();

android.os.Process

.killProcess(android.os.Process

.myPid());

android.os.Process.killProcess(android.os.Process.myTid());

android.os.Process.killProcess(android.os.Process.myUid());

}

})

.setNegativeButton("返回",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog,

int id) {

dialog.cancel();

}

});

AlertDialog alert = builder.create();

alert.show();

return true;

}

return false;

}

@Override

protected void onPause() {

// TODO Auto-generated method stub

super.onPause();

}

@Override

protected void onRestart() {

// TODO Auto-generated method stub

super.onRestart();

java.lang.System.out.println("onRestart");

}

@Override

protected void onResume() {

// TODO Auto-generated method stub

super.onResume();

java.lang.System.out.println("onResume");

}

@Override

protected void onStart() {

// TODO Auto-generated method stub

super.onStart();

java.lang.System.out.println("onStart");

}

@Override

protected void onStop() {

// TODO Auto-generated method stub

java.lang.System.out.println("onStop");

super.onStop();

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.activity_web, menu);

return true;

}

}

赞助本站

人工智能实验室

相关热词: webview

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港