在某种条件下,软键盘会遮挡键盘,这是无论你在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.()}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐