2012-08-06 240 views
1

在我的應用程序中,我有一個EditText。我如何使它不會自動啓動?喜歡:一旦他們打開活動,它會自動將鼠標設置爲EditText,鍵盤被打開,因此他們鍵入...EditText不會自動啓動

是否有任何我可以使它打開(鍵盤顯示和用戶可以鍵入),當他們點擊它?

+0

你試過將焦點設置呢? – sandrstar 2012-08-06 03:37:56

+0

你想要的確切答案是[this] [1]。 [1]:http://stackoverflow.com/questions/1555109/stop-edittext-from-gaining-focus-at-activity-startup – Dhrupal 2012-08-06 05:59:38

回答

1

好的,所以從你的問題中我發現你的EditText在開始活動時變得焦點。您可以使用以下命令禁用焦點來禁止鍵盤。

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

參觀此Close/hide the Android Soft Keyboard

+0

的偉大工程..謝謝=) – 2012-08-06 07:02:28

+0

歡迎你,快樂幫助你:) – Lucifer 2012-08-06 07:34:03

0

路西法的答案必須工作。但是當我遇到同樣的問題時,這個解決方案沒有用,而有人向我提出這個建議。

添加一個假佈局作爲您父級佈局中的第一個元素,並使其成爲可聚焦的。

像這樣:

<ParentLayout 
    ..... 
    ......> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     android:background="@android:color/transparent" 
     android:focusable="true" 
     android:focusableInTouchMode="true" > 
    </LinearLayout> 

    ...... 
    ...... 
    ...... 

</ParentLayout> 

這絕對有效,但最好的解決方法是:

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

我用Lucifer解決方案,它的工作,感謝Archie =) – 2012-08-06 07:03:15