【问题标题】:How to open Keyboard on Button click in android?如何在android中单击按钮打开键盘?
【发布时间】:2011-12-26 01:17:08
【问题描述】:

如何在 android 中单击按钮时打开键盘?

我想成为这样的人:

【问题讨论】:

    标签: android button keyboard


    【解决方案1】:
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    
    imm.showSoftInput(view, flags)
    

    一个例子可能是:

    InputMethodManager imm = (InputMethodManager) RouteMapActivity.this
        .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(mapView, InputMethodManager.SHOW_IMPLICIT);
    

    【讨论】:

    • 这是正确答案。其他答案会切换键盘,这在许多情况下是不可取的(即我们只想在用户单击清除搜索字段按钮时显示键盘,即使它已经显示)
    【解决方案2】:

    在按钮单击事件中编写此代码以切换键盘:

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
    

    【讨论】:

    • @Paresh .....点击按钮时仍然没有打开键盘,所以请给我正确的答案
    • @PareshMayani 如果我想打开特定语言的键盘。假设单击按钮我想打开印地语键盘,那么我必须做什么
    【解决方案3】:

    请试试这个

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
    

    【讨论】:

    • 谢谢桑迪,诀窍是 InputMethodManager.SHOW_FORCED 而不是 InputMethodManager。 SHOW_IMPLICIT。
    猜你喜欢
    • 1970-01-01
    • 2015-09-13
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 2019-11-19
    • 2012-11-15
    相关资源
    最近更新 更多