【问题标题】:How to hide the keyboard, and add text to EditText and move the cursor如何隐藏键盘,将文本添加到 EditText 并移动光标
【发布时间】:2015-12-30 09:37:04
【问题描述】:

我有一个EditText 和一个Button。当你按下EditText时,我不想显示keyboard,当你按下Button时,我想在EditText上输入一个数字1。

我想cursor 的观察并没有消失。

When you press the 1 1 writes When you press the Del licked Can be controlled in the text Without the appearance of the keyboard

【问题讨论】:

标签: android android-layout android-edittext android-button android-cursor


【解决方案1】:

试试这些代码:

your_edit_text.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            your_edit_text.setInputType(InputType.TYPE_NULL);
            EditText.setText("1");
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
             imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
             your_edit_text.setSelection(your_edit_text.getText().length()); // move cursor to end
        }

【讨论】:

    【解决方案2】:

    @Karim Michel。您可以使用

    对于第一种情况。隐藏键盘

       ETOBJ.setOnTouchListener(new View.OnTouchListener()
            {
                public boolean onTouch(View arg0, MotionEvent arg1)
                {
                    InputMethodManager inputManager = (InputMethodManager) context.
                    getSystemService(Context.INPUT_METHOD_SERVICE); 
                    inputManager.hideSoftInputFromWindow(
                    this.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS); 
                    return false;
                }
            });
    

    当按下按钮时,您可以使用

    setCursorVisible(false);
    setText("1");
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    • 2016-06-16
    相关资源
    最近更新 更多