android - 滚动到底部时 Android 11 中的键盘闪烁问题
问题描述
我已经编写了代码来在滚动时隐藏键盘。在 Android 11 之下它工作正常。在 Android 11 设备中滚动到底部并单击 edittext 键盘闪烁和消失的问题。
公共类 LinearLayoutThatDetectsSoftKeyboard 扩展 LinearLayout {
public LinearLayoutThatDetectsSoftKeyboard(Context context, AttributeSet attrs) {
super(context, attrs);
}
public interface Listener {
public void onSoftKeyboardShown(boolean isShowing);
}
private Listener listener;
public void setListener(Listener listener) {
this.listener = listener;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = MeasureSpec.getSize(heightMeasureSpec);
Activity activity = (Activity)getContext();
Rect rect = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
int screenHeight = activity.getWindowManager().getDefaultDisplay().getHeight();
int diff = (screenHeight - statusBarHeight) - height;
if (listener != null) {
listener.onSoftKeyboardShown(diff>128); // assume all soft keyboards are at least 128 pixels high
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
上面的代码适用于 Android 11.Android 11 以下的所有设备,而滚动到底部键盘未正确显示。请帮助
解决方案
推荐阅读
- android - Android Studio (3.1.4) 设计+蓝图的渲染问题
- jquery - 未捕获的类型错误:“#category-name”.val 不是函数
- http - 在同时请求时拨打 tcp I/O 超时
- android - 如何对 RecyclerView 项目单击执行多项操作?
- reactjs - React-konva 和 konva 不绘制模糊图像
- excel - Excel从行中移动电话号码
- sql - 检索平面结果 - BigQuery 标准 SQL
- javascript - 温斯顿:尝试在没有传输的情况下写入日志 - 使用默认记录器
- python - 将代码复制到同一程序但无法正常工作?切片索引必须是整数或 None 或具有 __index__ 方法
- ruby-on-rails - 使用acts_as votabable gem 来表示喜欢,并希望在用户喜欢后将心形颜色永久更改为红色