How can I get to know keyboard is open.actually my problem is that if keyboard is open then only I call for hide,not for always call hide. is there any method to check if keyboard is open ? currently I am using this method to hide 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);
Try GlobalLayout Listener like:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With