Android 解决由于使用SlidingMenu导致虚拟键盘挡住底部菜单栏的问题

最近发现当项目运行在5.0以上且带有虚拟键盘的手机上时会出现虚拟键盘挡住项目底部菜单栏的问题,试了若干方法,比如这个链接,但效果并不是很理想,后来发现原来是使用了SlidingMenu这个框架造成的,修改其中SlidingMenu下的fitSystemWindows即可解决这个问题:

/* (non-Javadoc)
	 * @see android.view.ViewGroup#fitSystemWindows(android.graphics.Rect)
	 */
	@SuppressLint("NewApi")
	@Override
	protected boolean fitSystemWindows(Rect insets) {
		int leftPadding = insets.left;
		int rightPadding = insets.right;
		int topPadding = insets.top;
		int bottomPadding = insets.bottom;
		if (CommonUtils.getSDKVersionCode(getContext())>=21&&CommonUtils.checkDeviceHasNavigationBar(getContext())) {
			Resources resources = getContent().getResources();
			int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
			if (resourceId > 0) {
				bottomPadding += resources.getDimensionPixelSize(resourceId);
			}
		}
		if (!mActionbarOverlay) {
			Log.v(TAG, "setting padding!");
			setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
		}
		return true;
	}
	
也就是如果系统版本高于5.0并且存在虚拟键盘时,计算一下虚拟键盘的高度,然后给bottomPadding加上虚拟键盘的高度即可!


猜你喜欢

转载自blog.csdn.net/superyu1992/article/details/69229869