这个是给ToolBar添加了android:fitsSystemWindows="true"且输入法设置adjustResize
Toolbar显示不完整,输入法展开时候,Toolbar被拉伸
解决办法,
办法一:
1、可以在布局的根布局下添加android:fitsSystemWindows="true"
我测试了华为和魅族和三星是没有问题的
办法二
1、给Toolbar设置Google推荐的高度(?attr/actionBarSize)
2、
// 1.先设置toolbar的高度
toolbar = (Toolbar) findViewById(R.id.toolbar);
ViewGroup.LayoutParams params = toolbar.getLayoutParams();
int statusBarHeight = getStatusBarHeight(this);
params.height += statusBarHeight;
Log.i("wxf","1:"+params.height);
Log.i("wxf","2:"+statusBarHeight);
toolbar.setLayoutParams(params);
// 2.设置paddingTop,以达到状态栏不遮挡toolbar的内容。
toolbar.setPadding(toolbar.getPaddingLeft(),
toolbar.getPaddingTop() + getStatusBarHeight(this),
toolbar.getPaddingRight(),
toolbar.getPaddingBottom());
/**
* 获取状态栏的高度
*
* @param context
* @return
*/
private int getStatusBarHeight(Context context) {
// 反射手机运行的类:android.R.dimen.status_bar_height.
int statusHeight = -1;
try {
Class<?> clazz = Class.forName("com.android.internal.R$dimen");
Object object = clazz.newInstance();
String heightStr = clazz.getField("status_bar_height").get(object).toString();
int height = Integer.parseInt(heightStr);
//dp--->px 因为padding的单位是px
statusHeight = context.getResources().getDimensionPixelSize(height);
} catch (Exception e) {
e.printStackTrace();
}
return statusHeight;
}
注意:用方法二Toolbar的高度一定要固定,不然toolbar会消失,这是我找到的比较靠谱的解决问题的方法
Comments | NOTHING