版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_35068744/article/details/78661925
这几天开发遇到ToolBar问题,是给我弄得整天心烦意乱,一直在各大站转圈圈的找问题,设置高度,设置权重,然后 ToolBar还是在顽强的石头一样。一动不动。提前说明,我是半路接手的项目,先上图看看吧。
然后再来一张对比图:
鲜明的对比出来了
可爱的我还想着什么情况,恩,我改改去:
- 权重(不行)
- 高度50dp(不行)
android:fitsSystemWindows=”true”
重点说下3吧。fitsSystemWindows只作用在sdk>=19的系统上就是高于4.4的系统,这个属性的view会自动添加一个值等于导航栏高度的paddingBottom我去看看代码去 去看看其他的布局做了什么; emmm。
看到Base的时候,眼睛亮了,
emmm:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
WindowManager.LayoutParams attributes = window.getAttributes();
attributes.flags |= flagTranslucentNavigation;
window.setAttributes(attributes);
getWindow().setStatusBarColor(Color.TRANSPARENT);
} else {
Window window = getWindow();
WindowManager.LayoutParams attributes = window.getAttributes();
attributes.flags |= flagTranslucentStatus | flagTranslucentNavigation;
window.setAttributes(attributes);
}
}
无视导航栏高度,所以导致了导航栏像一图那样子 一直定死在哪里
找到了原因,也证明想的没错。
附上老铁的链接:http://my.csdn.net/u010015108
感谢老铁。