Android的隐藏软键盘从EditText上,而不是失去光标 [英] Android Hide Soft Keyboard from EditText while not losing cursor

查看:429
本文介绍了Android的隐藏软键盘从EditText上,而不是失去光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来约尽可能<一个href="http://stackoverflow.com/questions/7665685/how-do-i-$p$pvent-the-software-keyboard-from-popping-up">this这让我中途有,但不大。 我有一个拨号器片段具有所有常用的按钮 s到输入号码,包括退格,所以我不知道所需要的软键盘。我也想给用户粘贴文本的功能(长按...作品每违约金),以及编辑什么已经进入了,所以我需要的光标。

I've come about as far as this which gets me halfway there, but not quite. I have a dialer Fragment that has all the usual Buttons to enter a number including backspace, so I don't need the soft keyboard. I'd also like to give the user the ability to paste text (long click... works fine per default), as well as to edit what has been entered so I need the cursor.

我发现,以确保如果用户点击里面的的EditText 是设置 inputType软键盘不会弹出的最简单方法来空 - 但是,杀死光标也是如此。

The easiest way I found to make sure the soft keyboard doesn't pop up if the user clicks inside the EditText is to set the inputType to null - but that kills the cursor as well.

那么,如何做我宣布我的的EditText ,我应该推出什么样的命令,让我的的EditText 字段从来没有表现出软键盘无论什么用户尝试,但仍保留粘贴功能,光标?

So, how do I declare my EditText and what kind of commands should I launch to have my EditText field never ever show the soft keyboard no matter what the user attempts, but still retain paste functionality and the cursor?

我也试过安卓windowSoftInputMode =stateAlwaysHidden在我的清单,但都无济于事。

I've also tried android:windowSoftInputMode="stateAlwaysHidden" in my manifest, but to no avail.

推荐答案

这为我工作:

        // Update the EditText so it won't popup Android's own keyboard, since I have my own.
    EditText editText = (EditText)findViewById(R.id.edit_mine);
    editText.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.onTouchEvent(event);
            InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }                
            return true;
        }
    });

这篇关于Android的隐藏软键盘从EditText上,而不是失去光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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