安卓:显示软键盘时自动对焦是一个EditText [英] Android: show soft keyboard automatically when focus is on an EditText

查看:204
本文介绍了安卓:显示软键盘时自动对焦是一个EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我展示使用一个输入框 AlertDialog 。该的EditText 对话时,我称自己是自动聚焦里面 AlertDialog.show(),但软键盘是不是自动显示。

I'm showing an input box using AlertDialog. The EditText inside the dialog itself is automatically focused when I call AlertDialog.show(), but the soft keyboard is not automatically shown.

如何使显示的对话框时,软键盘自动显示? (并没有物理/硬件键盘)。类似于如何当我preSS搜索按钮来调用全局搜索,软键盘会自动显示。

How do I make the soft keyboard automatically show when the dialog is shown? (and there is no physical/hardware keyboard). Similar to how when I press the Search button to invoke the global search, the soft keyboard is automatically shown.

推荐答案

您可以创建在的EditText AlertDialog ,然后拿到 AlertDialog 窗口。从那里,你可以通过调用使软键盘显示 setSoftInputMode

You can create a focus listener on the EditText on the AlertDialog, then get the AlertDialog's Window. From there you can make the soft keyboard show by calling setSoftInputMode.

final AlertDialog dialog = ...;

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if (hasFocus) {
            dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }
    }
});

这篇关于安卓:显示软键盘时自动对焦是一个EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆