解决方案 »

  1.   

    MainActivity.javapackage com.example.webview;import android.os.Bundle;  
    import android.app.Activity;  
    import android.view.GestureDetector.OnGestureListener;
    import android.view.GestureDetector;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.View.OnTouchListener;
    import android.view.Window;  
    import android.webkit.WebChromeClient;  
    import android.webkit.WebSettings;  
    import android.webkit.WebView;  
    import android.webkit.WebViewClient;  
    import android.widget.Toast;  
      
    public class MainActivity extends Activity implements OnTouchListener,OnGestureListener{  
      
    private final int verticalMinDistance = 100;
    private final int minVelocity = 200;

    WebView wv;  
        @Override  
        protected void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            getWindow().requestFeature(Window.FEATURE_PROGRESS);  
              
            setContentView(R.layout.activity_main);  
            wv = (WebView)findViewById(R.id.wv);
            wv.setOnTouchListener(this);
            WebSettings ws = wv.getSettings();  
            ws.setSupportZoom(true);
            ws.setBuiltInZoomControls(true);  
            
            wv.setWebChromeClient(new WebChromeClient(){  
                public void onProgressChanged(WebView view, int newProgress){  
                    MainActivity.this.setProgress(newProgress*100);  
                }  
            });  
            
            wv.setWebViewClient(new WebViewClient(){  
                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)  
                {  
                    Toast.makeText(MainActivity.this, "Sorry!" + description, Toast.LENGTH_SHORT).show();  
                }  
            });
            
            wv.loadUrl("http://www.baidu.com");  //默认登录网站
        }
    @Override
    public boolean onDown(MotionEvent arg0) {
    // TODO Auto-generated method stub
    return false;
    }
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
    float velocityY)
    {
    if (e1.getX() - e2.getX() > verticalMinDistance && Math.abs(velocityX) > minVelocity)
    {      
    if(wv.canGoForward()){  
                    wv.goForward();  
                }
            }

    //向左翻图片  
    if (e2.getX() - e1.getX() > verticalMinDistance && Math.abs(velocityX) > minVelocity)
    {      
    if(wv.canGoBack())  
                {  
                    wv.goBack();  
                }  
    }

    return false; 
    }
    @Override
    public void onLongPress(MotionEvent arg0) {
    // TODO Auto-generated method stub

    }
    @Override
    public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
    float arg3) {
    // TODO Auto-generated method stub
    return false;
    }
    @Override
    public void onShowPress(MotionEvent arg0) {
    // TODO Auto-generated method stub

    }
    @Override
    public boolean onSingleTapUp(MotionEvent arg0) {
    // TODO Auto-generated method stub
    return false;
    }

    @SuppressWarnings("deprecation")
    GestureDetector mygesture = new GestureDetector(this);
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    return mygesture.onTouchEvent(event);
    }

    activity_main.xml<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">    <WebView   
            android:id="@+id/wv"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"/></RelativeLayout>Manifest中加
    <uses-permission android:name="android.permission.INTERNET" />
      

  2.   


    <uses-permission android:name="android.permission.INTERNET" /> 权限没加吧?
      

  3.   

    在AndroidManifest.xml中加
    加在<uses-sdk android:minSdkVersion="10" />这个下面好了
    如:<uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.INTERNET" />
    代码以删