Juronis
Juronis

Reputation: 495

How to automatically pop-up keyboard?

I have Edit Text field where I have to input a password, but I have to push this field. How to automatically pop-up keyboard without touching the Edit Text?

There is an Edit text xml field:

<EditText
android:id="@+id/editPasswd"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:password="true"/>

Upvotes: 3

Views: 15880

Answers (3)

Liord
Liord

Reputation: 11

One line in the Java class:

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

Upvotes: 1

Nilzor
Nilzor

Reputation: 18593

I'm assuming you mean to automatically pop it up when the activity starts. If so, adding this to the activity-tag in the manifest solved it for me (unlike Erfan's answer):

android:windowSoftInputMode="stateVisible" 

Upvotes: 5

Sarwar Erfan
Sarwar Erfan

Reputation: 18068

Use this code in the point where you want to display the keyboard (may be in oCreate?)

    EditText myEditText = (EditText) findViewById(R.id.editPasswd);

    ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
        .showSoftInput(myEditText, InputMethodManager.SHOW_FORCED);

Upvotes: 8

Related Questions