如何自动弹出键盘?

时间:2011-01-26 12:22:33

标签: android xml keyboard

我有编辑文本字段,我必须输入密码,但我必须推送此字段。如何在不触摸编辑文本的情况下自动弹出键盘?

有一个编辑文本xml字段:

<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"/>

3 个答案:

答案 0 :(得分:7)

在您想要显示键盘的位置使用此代码(可能在oCreate中?)

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

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

答案 1 :(得分:5)

我假设您打算在活动开始时自动弹出它。如果是这样,将其添加到清单中的activity - 标签就可以解决它(与Erfan的回答不同):

android:windowSoftInputMode="stateVisible" 

答案 2 :(得分:1)

Java类中的一行:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
相关问题