android使用webview加载网页

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 package com.example.webview;   import android.os.Bundle; import android.annotation.SuppressLint; import android.app.Activity; import android.view.KeyEvent; import android.view.Menu; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient;     public  class  MainActivity extends Activity {        private  WebView webview;        @SuppressLint( "SetJavaScriptEnabled" )      @Override      protected  void  onCreate(Bundle savedInstanceState)      {          super.onCreate(savedInstanceState);          setContentView(R.layout.activity_main);          webview = (WebView) findViewById(R.id.webview);          WebSettings webSettings = webview.getSettings();          //设置WebView属性,能够执行Javascript脚本            webSettings.setJavaScriptEnabled( true );            //设置可以访问文件          webSettings.setAllowFileAccess( true );           //设置支持缩放          webSettings.setBuiltInZoomControls( true );          //加载需要显示的网页            webview.loadUrl( " http: //www.baidu.com"" target="_blank">http://www.baidu.com");            //设置Web视图            webview.setWebViewClient( new  webViewClient ());                  }               @Override      public  boolean onCreateOptionsMenu(Menu menu)      {          // Inflate the menu; this adds items to the action bar if it is present.          getMenuInflater().inflate(R.menu.main, menu);          return  true ;      }            @Override       //设置回退        //覆盖Activity类的onKeyDown(int keyCoder,KeyEvent event)方法        public  boolean onKeyDown( int  keyCode, KeyEvent event) {            if  ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {                webview.goBack();  //goBack()表示返回WebView的上一页面                return  true ;            }            finish(); //结束退出程序          return  false ;        }                //Web视图        private  class  webViewClient extends WebViewClient {            public  boolean shouldOverrideUrlLoading(WebView view, String url) {                view.loadUrl(url);                return  true ;            }        }     }


xml代码

1 2 3 4 5 6 7 8 9 10 11 12 <?xml version= "1.0"  encoding= "utf-8" ?>  " http: //schemas.android.com/apk/res/android" " target="_blank">http://schemas.android.com/apk/res/android"       android:orientation= "vertical"       android:layout_width= "fill_parent"       android:layout_height= "fill_parent"       >                   android:id= "@+id/webview"           android:layout_width= "fill_parent"           android:layout_height= "fill_parent"           /> 

更多相关文章

  1. android 播放视频保存的一些网页
  2. android view视图的层叠(叠加)
  3. Android 从网页中跳转到APP
  4. Android WebView访问SSL证书网页(onReceivedSslError)
  5. android mtk6732 camera otp 加载流程
  6. Android 9.0及以上WebView无法打开网页 ERR_CLEARTEXT_NOT_PERMI
  7. Android点击WebView网页中的email发送邮件调用
  8. Android 视图动画(View Animation) 使用详解

随机推荐

  1. 解决:Android(安卓)App 在运行时候按下 ho
  2. 简洁、高效、可自定义的开源的Android评
  3. "Android"牵手"iOS",WP滚蛋
  4. 设置Android(安卓)Studio启动时打开欢迎
  5. 从AIDL开始谈Android进程间Binder通信机
  6. Android跨进程通信:详解 Binder机制原理
  7. Android(安卓)资源加载机制剖析
  8. android listview仿iphone特效 弹性listv
  9. Android(安卓)标题背景渐变
  10. Android中的消息队列与消息循环:认识Handl