Hide soft keyboard on application load
Asked Answered
F

3

35

I have an application with an EditText element on the main view. This means that when my application is loaded the soft keyboard appears per default.

I would like to be able to hide the keyboard on load, so it does not show until i tap on the EditText view.

How do i manage this?

Fiscal answered 25/5, 2011 at 10:6 Comment(0)
K
29

You can do something easier. Add this to the LinearLayout (or any other layout that is the root):

<LinearLayout
...
android:focusable="true"
android:focusableInTouchMode="true"
...
/>
Kiwi answered 25/5, 2011 at 10:31 Comment(1)
The accepted answer didn't work for me, I already had stateHidden set. This suggestion works. I applied it to the XML layout instead: android:focusable="true" and android:focusableInTouchMode="true" on a parent view group.Williamswilliamsburg
T
5
InputMethodManager imm = 
    (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

This will hide in all situations (even when the EditView has focus):

 EditText editView = (EditText) findViewById(R.id.editTextConvertValue);
 editView.setInputType(InputType.TYPE_NULL);
Thorpe answered 25/5, 2011 at 10:8 Comment(0)
C
1

You can hide keyboard when page open easily

Add these two properties on root layout

android:focusable="true"
android:focusableInTouchMode="true"

Sample code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true">
Congruency answered 21/11, 2022 at 6:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.