上的EditText禁用键盘 [英] Disable keyboard on EditText

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

问题描述

我在做一个计算器。 所以,我做了我自己的按钮用数字和功能。 这位前pression一个必须计算,是在的EditText ,因为我希望用户也可以在的前pression中间添加数字或功能,所以与的EditText 我的光标。但我想禁用键盘当用户点击的EditText 。 我发现这个例子,它的确定为的Andr​​oid 2.3 ,但 ICS 禁用键盘,也光标。

I'm doing a calculator. So I made my own Buttons with numbers and functions. The expression that has to be calculated, is in an EditText, because I want users can add numbers or functions also in the middle of the expression, so with the EditText I have the cursor. But I want to disable the Keyboard when users click on the EditText. I found this example that it's ok for Android 2.3, but with ICS disable the Keyboard and also the cursor.

public class NoImeEditText extends EditText {

   public NoImeEditText(Context context, AttributeSet attrs) { 
      super(context, attrs);     
   }   

   @Override      
   public boolean onCheckIsTextEditor() {   
       return false;     
   }         
}

然后,我用这个 NoImeEditText 在我的 XML 文件

<com.my.package.NoImeEditText
      android:id="@+id/etMy"
 ....  
/>

我怎样才能让这个兼容使用的EditText ICS ??? 谢谢你。

How I can make compatible this EditText with ICS??? Thanks.

推荐答案

<一个href="https://groups.google.com/group/android-developers/browse_thread/thread/180530f680374493?pli=1">Here是一个网站,会给你你需要什么

Here is a website that will give you what you need

作为一个总结,它提供的链接 InputMethodManager 查看从Android开发人员。这将参照 getWindowToken 里面的查看 hideSoftInputFromWindow() InputMethodManager

As a summary, it provides links to InputMethodManager and View from Android Developers. It will reference to the getWindowToken inside of View and hideSoftInputFromWindow() for InputMethodManager

有一个更好的答案中给出的链接,希望这有助于。

A better answer is given in the link, hope this helps.

下面是一个例子消耗onTouch事件:

here is an example to consume the onTouch event:

editText_input_field.setOnTouchListener(otl);

private OnTouchListener otl = new OnTouchListener() {
public boolean onTouch (View v, MotionEvent event) {
        return true; // the listener has consumed the event
}
};

下面是从同一网站的另一个例子。这要求工作,但似乎是一个糟糕的主意,因为你的编辑框为空,将不再编辑:

Here is another example from the same website. This claims to work but seems like a bad idea since your EditBox is NULL it will be no longer an editor:

MyEditor.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
int inType = MyEditor.getInputType(); // backup the input type
MyEditor.setInputType(InputType.TYPE_NULL); // disable soft input
MyEditor.onTouchEvent(event); // call native handler
MyEditor.setInputType(inType); // restore input type
return true; // consume touch even
}
});

希望这点你在正确的方向。

Hope this points you in the right direction

这篇关于上的EditText禁用键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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