在某种条件下,软键盘会遮挡键盘,这是无论你在Menifest文件中如何设置键盘属性,都不理想,这个是Android系统的bug,以下代码用于解决问题:(至于什么条件下,不记得了,因为隔了好久时间才回来做个笔记,用于以后备用)
android.app.Activityandroid.graphics.Rectandroid.os.Buildandroid.view.Viewandroid.view.ViewTreeObserverandroid.widget.FrameLayoutAndroidBug5497Workaround { (Activity activity) { AndroidBug5497Workaround(activity)} View FrameLayout.LayoutParams = (Activity activity) { resourceId = activity.getResources().getIdentifier()= activity.getResources().getDimensionPixelSize(resourceId)FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.)= content.getChildAt().getViewTreeObserver().addOnGlobalLayoutListener(ViewTreeObserver.OnGlobalLayoutListener() { () { () { = .getHeight()= } possiblyResizeChildOfContent()} })= (FrameLayout.LayoutParams) .getLayoutParams()} () { usableHeightNow = computeUsableHeight()(usableHeightNow != ) { usableHeightSansKeyboard = .getRootView().getHeight()heightDifference = usableHeightSansKeyboard - usableHeightNow(heightDifference > (usableHeightSansKeyboard / )) { (Build.VERSION.>= Build.VERSION_CODES.) { .= usableHeightSansKeyboard - heightDifference + } { .= usableHeightSansKeyboard - heightDifference} } { .= } .requestLayout()= usableHeightNow} } () { Rect r = Rect().getWindowVisibleDisplayFrame(r)(r.- r.)} }
2.再出现这种问题的Activity的onCreate方法中调用以下代码,解决问题:
(Bundle savedInstanceState) { .onCreate(savedInstanceState)setContentView(R.layout.)AndroidBug5497Workaround.()}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦