3

I have an Android activity and there is one EditText in the whole layout. For some reason, whenever the activity starts, the keyboard comes up. I have tried all of the following things:

  • Placing these two in OnStart:

    FindViewById<EditText> (Resource.Id.searchText).ClearFocus ();
    FindViewById<EditText> (Resource.Id.searchText).Selected = false;
    
  • Adding a LinearLayout with these two properties:

    android:focusable="true" android:focusableInTouchMode="true"
    
  • Adding the following tag inside another View on the layout:

    android:focusable="true" android:focusableInTouchMode="true"
    
  • Adding this to my activity manifest:

    android:windowSoftInputMode="stateHidden"
    

But still, the keyboard opens when the activity opens. What could I be doing wrong?

4

5 に答える 5

4

これを試して -this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

于 2013-08-23T16:45:23.650 に答える
0

デフォルトでは、Android は最初のフォーカス可能なオブジェクトをターゲットにします。kirankk の回答は標準アクティビティで機能しますが、カスタム ビューで を使用している場合、はるかに簡単なオプション (標準アクティビティでも機能します) は、テキスト ビューが含まれてDialogFragmentいる ViewGroup (つまりLinearLayout/ ) をフォーカス可能にし、RelativeLayoutタッチモードでフォーカス可能。これは AXML から行うことができ、TextViewフォーカス可能な最初のビューになることを防ぎます。

于 2013-09-10T10:35:36.093 に答える