Why does the Android soft keyboard appear when it appears?

Can someone explain why the soft keyboard appears and disappears when it does?

I have a layout with many different controls, mostly EditTexts and Buttons. When I first show this page, the EditText at the top of the layout has focus, and the soft keyboard closes the bottom 45% of the screen.

I assumed that the keyboard was there because EditText had focus, so I decided to give a button at the bottom of my page, and focus instead.

butDone.setFocusableInTouchMode(true); bResult = butDone.requestFocus(); 

... right after setContentView (). This worked the same as pressing a button. Bobton got the focus, and EditText no longer focused, but the keyboard was still there. In the end, I got rid of the keyboard through

 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 

but it’s clear that my theory that EditText has focus was wrong. So can someone explain the β€œrules” about what makes the keyboard appear when it does, or a link to these rules? Thanks in advance!

+6
source share
1 answer

By default, the first EditText will receive focus if you have not defined anything about focus in the XML layout.

Check this answer for more info. You should use this solution if you do not want the keyboard to appear instead of rejecting the keyboard.

0
source

All Articles