Search code examples
androidlistviewandroid-edittextandroid-keypad

Minimise Keyboard when you have an EditText Field in an Activity


I am creating an app which contains multiple activities. A number of my activities have an 'EditText' field. As soon as I enter these activities, the keyboard instantly pops up assuming I want to type something straight away.

Does anyone have a simple code I can add into my java file that will prevent the keyboard to pop up by default because there is an 'EditText' field.

If you can also specify where to place the line of code such as whether it goes in the onCreate method etc will be appreciated.

I'm assuming the following will work, but where do I need to place it?

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

Solution

  • The above code can be placed in the onCreate method.

    p.s I figured this out after some trial and error, hope it helps others