如何隐藏虚拟键盘 [英] how to hide the virtual keyboard

查看:170
本文介绍了如何隐藏虚拟键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不希望显示的虚拟键盘。

I don't want to show the virtual keyboard.

我试过下面的方法,但它并没有任何区别。

I tried the below method but it doesn't make any difference.

InputMethodManager imm =     InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(enter_count.getWindowToken(), 0);

enter_count是我的编辑文本 我曾尝试在InputMethod经理读了,但不能跟着它。

enter_count is my edit text I have tried reading up on the InputMethod Manager but can't follow it.

我可以将我的编辑文本的输入类型称为enter_count如下:

I can set the input type of my edit text called enter_count as follows

enter_count.setInputType( InputType.TYPE_NULL );

但我不能指定只接受数字输入

but then I can't specify to only accept numeric input

能否请你给我一个合理的解决方案根本就没有,而不会丢失只接受了物理键盘上输入数字的能力,显示虚拟键盘。

Can you please give me a reasonable solution to simply not show the virtual keyboard without losing the ability to only accept numeric input on the physical keyboard.

推荐答案

这个怎么样?

EditText editText = (EditText) findViewById(R.id.edt_hello);

editText.setKeyListener(new NumberKeyListener() {

    @Override
    public int getInputType() {
        return InputType.TYPE_NULL;
    }

    @Override
    protected char[] getAcceptedChars() {
        return new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
    }
});

这篇关于如何隐藏虚拟键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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