效果对比图片先走
解决前效果图

T_X0~JU{WQ2FC1W$M})J%1S.jpg
解决完成后效果图

0EBFD68FC050B16866B81321E0FD9C62.jpg
/**
* @author colin
* @Date 2020/7/20
* @ClassTag :
*/
public class AndroidBug5497Workaround {
public static void assistActivity(Activity activity) {
new AndroidBug5497Workaround(activity);
}
private View mChildOfContent ;
private int usableHeightPrevious;
private FrameLayout.LayoutParams frameLayoutParams ;
private AndroidBug5497Workaround(Activity activity) {
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
possiblyResizeChildOfContent();
}
});
frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
}
private void possiblyResizeChildOfContent() {
int usableHeightNow = computeUsableHeight();
if (usableHeightNow != usableHeightPrevious) {
int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
int heightDifference = usableHeightSansKeyboard - usableHeightNow;
if (heightDifference > (usableHeightSansKeyboard / 4)) {
// keyboard probably just became visible
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
} else {
// keyboard probably just became hidden
frameLayoutParams.height = usableHeightSansKeyboard;
}
mChildOfContent.requestLayout();
usableHeightPrevious = usableHeightNow;
}
}
private int computeUsableHeight() {
Rect r = new Rect();
mChildOfContent.getWindowVisibleDisplayFrame(r);
return (r.bottom - r.top);// 全屏模式下:return r.bottom
}
}
使用方式

image.png
//在Activity中初始化
AndroidBug5497Workaround.assistActivity(this);
<!--富文本编辑-->
<activity
android:name=".ui.html.activity.RichEditorActivity"
android:windowSoftInputMode="adjustPan"/>
一定要在 清单文件对应的Activity中设置 adjustPan属性
网友评论