【问题标题】:How to automatically pop-up keyboard?如何自动弹出键盘?
【发布时间】:2011-06-15 19:48:42
【问题描述】:

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

有一个编辑文本 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"/>

【问题讨论】:

    标签: android xml keyboard


    【解决方案1】:

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

        EditText myEditText = (EditText) findViewById(R.id.editPasswd);
    
        ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
            .showSoftInput(myEditText, InputMethodManager.SHOW_FORCED);
    

    【讨论】:

    • 这对我有用:
    【解决方案2】:

    我假设您的意思是在活动开始时自动弹出它。如果是这样,将其添加到清单中的 activity-tag 为我解决了它(不像 Erfan 的回答):

    android:windowSoftInputMode="stateVisible" 
    

    【讨论】:

      【解决方案3】:

      Java 类中的一行:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-07
        • 2011-01-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-06
        • 2021-01-21
        相关资源
        最近更新 更多