美文网首页
android fitSystemWindow属性

android fitSystemWindow属性

作者: yunhen | 来源:发表于2018-07-05 18:11 被阅读50次

fitsSystemWindows只作用在sdk>=19的系统上就是高于4.4的系统
android:fitsSystemWindows="true"

1. 当设置了透明状态栏(StatusBar)时:

当为此activity设置了

<item name="android:windowTranslucentStatus">true</item>
//或者
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT{
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}

如果有以上两种情况之一,我们的状态栏(StatusBar)就会变成透明,并且布局会扩展到StatusBar的位置,同时,所有设置了android:fitsSystemWindows=”true”属性的view会自动添加一个值等于状态栏高度的paddingTop

2. 当设置了透明导航栏(NavigationBar)时:

当为此activity设置了:

<item name="android:windowTranslucentNavigation">true</item>
//或者
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}

如果有以上两种情况之一,我们的导航栏(NavigationBar)就会变成透明,并且布局会扩展到NavigationBar的位置,同时,所有设置了android:fitsSystemWindows=”true”属性的view会自动添加一个值等于导航栏高度的paddingBottom

获取statusbar的高度:

public float getStatusBarHeight() {
    float result = 0;
    int resourceId = getResources().
getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = getResources().getDimension(resourceId);
    }
    return result;
}   //返回值就是状态栏的高度,得到的值是像素

获取NavigationBar高度

public float getNavigationBarHeight() {
    float result = 0;
    int resourceId = getResources().
getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = getResources().getDimension(resourceId);
    }
    return result;
}   //返回值就是导航栏的高度,得到的值是像素

相关文章

网友评论

      本文标题:android fitSystemWindow属性

      本文链接:https://www.haomeiwen.com/subject/hezpuftx.html