Prevent EditText from automatically focusing

≯℡__Kan透↙ 提交于 2019-12-01 10:12:21

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

Nitin V. Patil

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)]

Add this to manifest file...

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

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.

Zee

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"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!