3

I am writing a calculator for Android, for inputting expression I use EditText. As I create my buttons - I do not need a software keyboard, but I want to change the cursor position, text selection, copy, paste. In a word - everything as it is, only the virtual keyboard is not displayed. In version 2.3 I could write:

EditText.setInputType (InputType.TYPE_NULL);

and it worked perfectly. In version 4 of the cursor is not displayed, the menu does not work, etc. Tried a bunch of ways - you can not move the cursor, the keyboard is displayed, and it was never really explained.

InputMethodManager imm = (InputMethodManager)getSystemService(
    Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0); //cursor not showing
------------------------------------------------------------------------
getWindow().setSoftInputMode(
    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); //not working

I want to make it as in Panecal, MobiCalc Free, Scientific Calculator. I would be happy with any helpful suggestions on this. P.S. Sorry for my English.

4

2 回答 2

2

From the link posted below, here is an example to consume on touch for an Edittext

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

The above answer was taken from - how to block virtual keyboard while clicking on edittext in android?

This might work too getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

于 2012-11-10T13:51:52.157 回答
0

textIsSelectable对此的确切解决方案是将EditText 中的标志设置为true。这将保留光标,您将能够使用基本的选择/复制/剪切/粘贴等功能。您可以在 xml 布局中设置它,如下所示:

您可以像这样以编程方式设置它:

EditText edit_text = (EditText) findViewById(R.id.editText);
edit_text.setTextIsSelectable(true);

或者在您的 XML 布局中:

<EditText
    ...
    android:textIsSelectable="true"
/>

对于使用 API 10 及以下版本的任何人,此处提供了 hack:https ://stackoverflow.com/a/20173020/7550472

于 2017-02-14T20:59:24.330 回答