How to remove focus without setting focus to another control?

后端 未结 11 1788
终归单人心
终归单人心 2020-11-28 22:02

I like my UIs to be intuitive; each screen should naturally and unobtrusively guide the user on to the next step in the app. Barring that, I strive to make things as confusi

11条回答
  •  执笔经年
    2020-11-28 22:07

    android:descendantFocusability="beforeDescendants"

    using the following in the activity with some layout options below seemed to work as desired.

     getWindow().getDecorView().findViewById(android.R.id.content).clearFocus();
    

    in connection with the following parameters on the root view.

    
    

    https://developer.android.com/reference/android/view/ViewGroup#attr_android:descendantFocusability

    Answer thanks to: https://forums.xamarin.com/discussion/1856/how-to-disable-auto-focus-on-edit-text

    About windowSoftInputMode

    There's yet another point of contention to be aware of. By default, Android will automatically assign initial focus to the first EditText or focusable control in your Activity. It naturally follows that the InputMethod (typically the soft keyboard) will respond to the focus event by showing itself. The windowSoftInputMode attribute in AndroidManifest.xml, when set to stateAlwaysHidden, instructs the keyboard to ignore this automatically-assigned initial focus.

    
    

    great reference

提交回复
热议问题