如何自动弹出键盘?

Jur*_*nis 2 xml keyboard android

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

有一个Edit text 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"/>
Run Code Online (Sandbox Code Playgroud)

Sar*_*fan 7

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

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

    ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
        .showSoftInput(myEditText, InputMethodManager.SHOW_FORCED);
Run Code Online (Sandbox Code Playgroud)

  • 这适用于我:<activity android:name =".first"android:windowSoftInputMode ="stateAlwaysVisible"> (3认同)

Nil*_*zor 5

我假设你的意思是在活动开始时自动弹出它.如果是这样,将它添加到activity清单中的-tag解决了它(与Erfan的答案不同):

android:windowSoftInputMode="stateVisible" 
Run Code Online (Sandbox Code Playgroud)