How to prevent virtual keyboard displaying when long-press on EditText Widget?

前端 未结 2 869
灰色年华
灰色年华 2021-01-06 22:29

I\'ve got an EditText widget in my app which I have set to read-only, and I want to know when the user long-presses on it. I don\'t want the virtual keyboard to popup if the

相关标签:
2条回答
  • 2021-01-06 23:11
    button.setOnLongClickListener (View.OnLongClickListener l(){
    
    //override the method  
    
    //then do this
    
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
    });
    
    0 讨论(0)
  • 2021-01-06 23:25

    Try using this and options available.

    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    

    My problem was that when ever my activity started, kepyboard poped up automatically if there is an EditText. So, I used the above in OnCreate(). Try using different options instead of ".SOFT_INPUT_STATE_ALWAYS_HIDDEN"

    0 讨论(0)
提交回复
热议问题