This is the code I use to detect when the Keyboard Height changes.
Only the problem is that the Statur Bar color disappears and turns white when this code runs.
ViewCompat.setOnApplyWindowInsetsListener(this.getWindow().getDecorView(), (v, insets) -> {
int keyboardHeight = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom;
//Do your job here
Log.d("Keyboard height: ", String.valueOf(keyboardHeight));
SharedPreferences preferences = this.getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (keyboardHeight > 0) {
bottom.getLayoutParams().height = 0;
editor.putInt("keyboard_height", keyboardHeight);
} else {
bottom.getLayoutParams().height = preferences.getInt("keyboard_height", 500);
}
editor.apply();
return insets;
});
Any alternative code that doesn't alter the Status Bar color?
Or any way to programmatically re-add the Status Bar color after this code runs?
You can solve this by consuming the insets dispatch event by returning
WindowInsetsCompat.CONSUMEDinstead ofinsetsPer documentation:
UPDATE:
Well, that does seem to make the activity full screen, even intersects with the navigation bar as well.
Now to fix that return the following instead: