Android的隐藏软键盘从EditText上,而不是失去光标光标、而不是、键盘、Android

由网友(人走茶凉i)分享简介:我来约尽可能this这让我中途有,但不大。我有一个拨号器片段具有所有常用的按钮 s到输入号码,包括退格,所以我不知道所需要的软键盘。我也想给用户粘贴文本的功能(长按...作品每违约金),以及编辑什么已经进入了,所以我需要的光标。I've come about as far as this which gets me...

我来约尽可能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;
        }
    });
阅读全文

相关推荐

最新文章