我在做一个计算器。
所以,我做了我自己的按钮
用数字和功能。
这位前pression一个必须计算,是在的EditText
,因为我希望用户也可以在的前pression中间添加数字或功能,所以与的EditText
我的光标
。但我想禁用键盘
当用户点击的EditText
。
我发现这个例子,它的确定为的Android 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.
推荐答案
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
相关推荐
最新文章