2012-05-07 151 views
2

我在我的布局中的edittext,像这样:禁用软键盘

//...  
<EditText 
    android:id="@+id/editText_username" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:hint="@string/string_username" > 
</EditText> 
//... 

并显示布局时,键盘会出现与重点edittext,但是这只是发生在ICS ...我不希望键盘自动出现,只需点击edittext即可。

我该怎么做?

+0

您是否尝试将焦点设置为onResume()中的其他内容? – onit

回答

7

键盘的初始状态是在你的Android清单配置,如:

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

使用

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

在你的代码。参见:Close/hide the Android Soft Keyboard

0

检查this answer。基本上,只需将android:windowSoftInputMode="stateHidden"添加到清单中的活动即可。这将导致活动启动时隐藏键盘。

1

这里有一个可能性:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 

您还可以找到更多的可能性in this topic