开发者

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"
开发者_StackOverflow中文版android:password="true"/>


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);


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" 


One line in the Java class:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜