2016-10-05 41 views
1

我有一個WebView其中有一個RelativeLayout父。 在WebView當我點擊某個特定按鈕時,它會加載另一個網址。我想禁用該網址上的鍵盤。以及我在shouldoverrideurlloading(WebView視圖,Url Url)方法中獲得的url。Android:如何禁用某些特定頁面的webview上的鍵盤?

<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" 
    android:background="@drawable/background" 
    android:gravity="center_horizontal" 
    android:orientation="vertical" 
    tools:context="com.xenopsi.benchmark.BrowserActivity"> 

    <WebView 
     android:id="@+id/browserView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     android:scrollbars="none"/> 

    </RelativeLayout> 

在這個方法我做:

relativeLayout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); 
webView.setFocusable(false); 
webView.setFocusableInTouchMode(true); 

,但仍當我在該網頁的文本字段挖掘,鍵盤仍然所示。 如果我做了onCreate()活動的方法相同的代碼,其工作正常,

但我的問題是想在我的頁面加載時禁用它的方法shouldOverrideUrlLoading

+0

參考[此](http://stackoverflow.com/a/30440309/5148289)回答 –

+0

我已經嘗試過,所有的事情在oncreate方法中工作,但我想爲特定頁面執行此操作時,shouldOverrideUrlLoading方法檢測到我的網址。對於其他頁面,我想顯示我的鍵盤,但不是該頁面。 – ankur

回答

0

歐凱你提到你要隱藏鍵盤的特定鏈接,做這樣的事情,

public boolean shouldOverrideUrlLoading(WebView view, String url) { 
    Log.e("Loading URL", url); 

    view.loadUrl(url); 

    if(url.equals(yourUrl)){ 
     // hide keyboard 
    } else { 
     // unhide keyboard 
    } 
    return true; 
} 

我希望這將有助於..

編碼快樂..

+0

我已經試過這個,但仍然沒有解決方案。 – ankur