2012-11-23 41 views
0

我有一個顯示視圖的活動。該視圖由各種小部件組成,其中一個是多行EditText。當視圖膨脹時,軟鍵盤出現,我該如何禁用它?如何隱藏軟鍵盤?

東西我曾嘗試:

從EditText上內去除佈局以下。

<requestFocus /> 

創建以下方法,然後從oncreate方法調用它(分辨率是EditText)。

private void hideSoftKeyboard() { 

     InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.hideSoftInputFromWindow(resolution.getWindowToken(), 0); 

    } 

回答

1

添加到您的清單文件

android:windowSoftInputMode="stateHidden" 

<activity android:name=".youractivity" 
       android:windowSoftInputMode="stateHidden" 

    </activity> 
+0

嘿謝謝做的竅門! – turtleboy

0

隱藏它通過:

editText.setInputType(InputType.TYPE_NULL); 

,當你需要顯示它使用:

editText.setInputType(InputType.TYPE_CLASS_TEXT); 
editText.requestFocus(); 
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
mgr.showSoftInput(editText, InputMethodManager.SHOW_FORCED); 
0
android:descendantFocusability="beforeDescendants" 
android:focusableInTouchMode="true" 

在頂視圖中添加這兩條線

例如:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:descendantFocusability="beforeDescendants" <----- 
    android:focusableInTouchMode="true" > <----- 
    .... 
    EditText 
    ..... 
    </RelativeLayout> 
2

當只不過是你去上你的應用程序的Manifest.xml然後寫了這個代碼。

<activity android:name="yourActName" 
     android:configChanges="keyboardHidden" > 
    </activity>