【发布时间】:2023-01-28 00:27:15
【问题描述】:
这是我用来检测 Keyboard Height 何时更改的代码。
唯一的问题是当这段代码运行时,Statur Bar 颜色消失并变成白色。
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;
});
任何不改变Status Bar颜色的替代代码?
或者在此代码运行后以编程方式重新添加Status Bar颜色的任何方式?
【问题讨论】: