2016-09-09 111 views
0

我有一個webview,我發送了一個URL。頁面顯示沒問題,但我無法與顯示的頁面交互。我不能點擊按鈕,我只是一個前... 你有這個問題的想法?Android Webview點擊

我的代碼:

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_web); 
    WebView myWebView = (WebView) findViewById(R.id.webview); 
    myWebView.loadUrl("www.google.com");  
    myWebView.setWebViewClient(new WebViewClient()); 
} 

回答

3

可以的onclick添加下面的方法來的WebView:

webView.setOnTouchListener(new View.OnTouchListener() { 

     public final static int FINGER_RELEASED = 0; 
     public final static int FINGER_TOUCHED = 1; 
     public final static int FINGER_DRAGGING = 2; 
     public final static int FINGER_UNDEFINED = 3; 

     private int fingerState = FINGER_RELEASED; 


     @Override 
     public boolean onTouch(View view, MotionEvent motionEvent) { 

      switch (motionEvent.getAction()) { 

       case MotionEvent.ACTION_DOWN: 
        if (fingerState == FINGER_RELEASED) fingerState = FINGER_TOUCHED; 
        else fingerState = FINGER_UNDEFINED; 
        break; 

       case MotionEvent.ACTION_UP: 
        if(fingerState != FINGER_DRAGGING) { 
         fingerState = FINGER_RELEASED; 

         // Your onClick codes 
         Toast.makeText(WebActivity.this,"Click Detected",Toast.LENGTH_LONG).show();    

        } 
        else if (fingerState == FINGER_DRAGGING) fingerState = FINGER_RELEASED; 
        else fingerState = FINGER_UNDEFINED; 
        break; 

       case MotionEvent.ACTION_MOVE: 
        if (fingerState == FINGER_TOUCHED || fingerState == FINGER_DRAGGING) fingerState = FINGER_DRAGGING; 
        else fingerState = FINGER_UNDEFINED; 
        break; 

       default: 
        fingerState = FINGER_UNDEFINED; 

      } 

      return false; 
     } 
    }); 

如果裏面有web視圖按鈕,您的網頁視圖中顯示頁面會處理that.You不能得到該回調。

+0

顯示器上的部分//在上面的代碼你的onClick代碼的ttoast。 – kgandroid

+0

我不能點擊我的網絡視圖,我使用你的方法,但它不工作:/ – Guillaume

+0

粘貼你的代碼在pastebin中,並給我鏈接...讓我看看 – kgandroid

0

試試這個代碼,我認爲它會工作:

WebSettings webSettings = myWebView.getSettings(); 
webSettings.setJavaScriptEnabled(true);