Prevent EditText from automatically focusing

前端 未结 5 398
心在旅途
心在旅途 2021-01-14 08:43

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

相关标签:
5条回答
  • 2021-01-14 08:55

    Try these for Xamarin.Android (Cross Platform)

    this.Window.SetSoftInputMode (SoftInput.StateHidden);
    

    Or

    Add this to manifest,

    [Activity(Label = "SampleApp", MainLauncher = true, Icon = "@drawable/icon", WindowSoftInputMode = SoftInput.StateHidden)]
    
    0 讨论(0)
  • 2021-01-14 08:57

    Android by default targets the first focusable object. Whilst kirankk's answer works for standard activities, if you're using a DialogFragment with a custom view, the much easier option (which incidentally also works for standard activities) is to make the ViewGroup (ie LinearLayout/RelativeLayout) that your text view is contained in focusable and focusable in touch mode. This can be done from the AXML and prevents the TextView being the first focusable view.

    0 讨论(0)
  • 2021-01-14 09:01

    I know this is super old, but find that adding this to your root view in the XML file usually helps to prevent this issue:

     android:descendantFocusability="beforeDescendants"
     android:focusableInTouchMode="true"
    
    0 讨论(0)
  • 2021-01-14 09:08

    Add this to manifest file...

    <activity android:name=".YourActivity" android:windowSoftInputMode="stateHidden"  />
    
    0 讨论(0)
  • 2021-01-14 09:21

    Try this -this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    0 讨论(0)
提交回复
热议问题