2013-08-23 89 views
3

我有一個Android活動,並且在整個佈局中有一個EditText。出於某種原因,只要活動開始,鍵盤就會出現。 我已經試過下面的事情都防止EditText自動對焦

  • 配售這兩個在OnStart

    FindViewById<EditText> (Resource.Id.searchText).ClearFocus(); 
    FindViewById<EditText> (Resource.Id.searchText).Selected = false; 
    
  • 添加LinearLayout與這兩個屬性:

    android:focusable="true" android:focusableInTouchMode="true" 
    
  • 添加在另一個內部的以下標籤上的佈局:

    android:focusable="true" android:focusableInTouchMode="true" 
    
  • 添加該到我的活動清單:

    android:windowSoftInputMode="stateHidden" 
    

仍然,活動開啓時鍵盤打開。我可能做錯了什麼?

+0

爲了誰正在查看,並考慮標記爲重複,請不要「T。我讀過[這個問題](http://stackoverflow.com/questions/1555109/stop-edittext-from-gaining-focus-at-activity-startup)並嘗試了一切。 –

回答

4

試試這個 - this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

1

添加到這個清單文件......

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

正如我在這個問題中說過的,我已經添加了這個:( –

0

Android的默認目標的第一個可聚焦的對象。雖然kirankk的答案適用於標準活動,但如果您使用具有自定義視圖的DialogFragment,則更簡單的選項(順便也適用於標準活動)是讓ViewGroup(即LinearLayout/RelativeLayout)包含文本視圖在觸摸模式下可調焦和可對焦。這可以通過AXML來完成,並且可以防止TextView成爲第一個可以聚焦的視圖。

6

嘗試這些爲Xamarin.Android(跨平臺)

this.Window.SetSoftInputMode (SoftInput.StateHidden); 

或者

添加此體現,

[Activity(Label = "SampleApp", MainLauncher = true, Icon = "@drawable/icon", WindowSoftInputMode = SoftInput.StateHidden)] 
+1

+1)史詩。 – Matosha