2015-12-29 17 views
0

我正在使用一個webView(全屏),它在需要時有自己的鍵盤。 我想禁用每次彈出的android鍵盤。禁用整個應用程序的鍵盤(Android)

我試過用hideSoftInputFromInputMethod(getCurrentFocus().getWindowToken(), 0);這樣做,但它不起作用。也不android:windowSoftInputMode="stateAlwaysHidden"
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

+0

的可能的複製[安卓:退格鍵的WebView/BaseInputConnection](http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection) – marcinj

回答

0

您必須添加android:windowSoftInputMode="stateAlwaysHidden"在清單文件中的每個活動。像這樣的例子

<activity 
     android:name=".MainActivity" 
     android:windowSoftInputMode="stateAlwaysHidden" /> 
+0

正如我在我的文章中提到的 - 我已經嘗試過。不幸的是,由於某種原因 – BVtp

0

使用下面的函數,並調用它的WebView的onTouch():

public static void hideSoftKeyboard(Activity activity) { 
    try { 
     InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); 
     inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

} 
+0

沒有幫助,但我沒有EditText。所有的「編輯文本」都是webview。 – BVtp

0

加入您的layout.xml

android:descendantFocusability="blocksDescendants" 

希望按照主(父)佈局代碼它會工作。並設置以下屬性在你的WebView

android:focusable="false" 
android:focusableInTouchMode="true" 



See it: 
<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:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:descendantFocusability="blocksDescendants" 
    android:paddingBottom="@dimen/activity_vertical_margin"  tools:context=".MainActivityFragment"> 

    <WebView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:focusable="false" 
     android:focusableInTouchMode="false"> 
    </WebView> 
</RelativeLayout> 
+0

也不工作.. – BVtp

0
if (mActivity.getCurrentFocus() != null) { 
      InputMethodManager inputMethodManager = (InputMethodManager) mActivity.getSystemService(mActivity.INPUT_METHOD_SERVICE); 
      inputMethodManager.hideSoftInputFromWindow(mActivity.getCurrentFocus().getWindowToken(), 0); 
     } 
0

試試這個:

<activity   
      android:configChanges="keyboard|keyboardHidden" 
      android:windowSoftInputMode="stateAlwaysHidden"> 
+0

不幸的是沒有變化:/ – BVtp