How can I find out that the keyboard is open

How can I find out that the keyboard is open. Usually my problem is that if the keyboard is open, then I only invoke the hide, and not always invoke the hide. is there any way to check if the keyboard is open? I am currently using this method to hide the keyboard.

EditText myEditText = (EditText) findViewById(R.id.myEditText); View view = this.getCurrentFocus(); if (view != null) {ditText) findViewById(R.id.myEditText); View view = this.getCurrentFocus(); if (view != null) { Inp` im.hideSoftInputFromWindow(view.getWindowToken(), 0); 
+6
source share
1 answer

Try the GlobalLayout listener, for example:

  main_layout.getViewTreeObserver().addOnGlobalLayoutListener( new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect r = new Rect(); // r will be populated with the coordinates of your view // that area still visible. main_layout.getWindowVisibleDisplayFrame(r); int heightDiff = main_layout.getRootView().getHeight()-(r.bottom -r.top); //if(hightDiff>100) --> It may be keyboard. } }); 

Replace main_layout with your layout.

+1
source

All Articles