Search code examples
androidxmlandroid-layoutandroid-keypad

Trying to get Android keyboard to popup on activity startup


I want the Android Keyboard to pop-up on the startup of my activity. A simple google search shows that you just have to requestFocus which I do in my .xml, but it still doesn't pop up. Am I making any minor mistake that is causing this not to work?

Testing on:

Physical 4.1 Emulator 2.2

layout.xml:

<EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:ems="10"
        android:hint="To:"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

Solution

  • This works:

    myEditText.setOnFocusChangeListener( new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });