2012-05-07 203 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