I want to check when the keyboard is up when android:windowSoftInputMode="adjustNothing"
.
The link here didn't work for me in this state.
Asked
Active
Viewed 169 times
1 Answers
0
If you set it to adjustNothing, it's still not possible to detect whether or not the keyboard is visible using his code snippet. To work around this, check this code below.
View activityRootView = findViewById(R.id.activityRoot);
activityRootView.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.
activityRootView.getWindowVisibleDisplayFrame(r);
int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});

Karthik
- 59
- 3
-
This is not being called when you have 'adjustNothing', only first time screen opens – Boy Nov 27 '20 at 11:15