在某种条件下,软键盘会遮挡键盘,这是无论你在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 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦