2012-11-23 198 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>