简体   繁体   English

如何自动弹出键盘?

[英]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: 有一个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"/>

Use this code in the point where you want to display the keyboard (may be in oCreate?) 在要显示键盘的位置使用此代码(可能在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): 如果是这样,将其添加到清单中的activity标签为我解决了它(不像Erfan的回答):

android:windowSoftInputMode="stateVisible" 

Java类中的一行:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM