美文网首页Android 开发
状态栏及导航栏 fitsSystemWindows

状态栏及导航栏 fitsSystemWindows

作者: BugFree张瑞 | 来源:发表于2018-12-04 14:03 被阅读3次

在 android 的 XML 中设置 fitsSystemWindows 属性的分析:
网上的文章都说得不太清楚

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

android:fitsSystemWindows="true"

这个属性可以给任何 view 设置,只要设置了这个属性此 view 的所有 padding 属性失效。而且只有在设置了透明状态栏 (StatusBar) 或者导航栏 (NavigationBar) 时此属性才会生效。

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

当为此 activity 设置了:

<item name="android:windowTranslucentStatus">true</item>

同时,所有设置了 android:fitsSystemWindows=”true” 属性的 view 会自动添加一个值等于状态栏高度的 paddingTop

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

当为此 activity 设置了:

<item name="android:windowTranslucentNavigation">true</item>

同时,所有设置了 android:fitsSystemWindows=”true” 属性的 view 会自动添加一个值等于导航栏高度的 paddingBottom

3. 附加一个获取 statusbar 的和一个获取 NavigationBar 高度的代码:

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




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

有时候,当软键盘弹出时,会将我们的 view 顶上去:

android:windowSoftInputMode="adjustResize|stateHidden"

相关文章

  • 状态栏及导航栏 fitsSystemWindows

    在 android 的 XML 中设置 fitsSystemWindows 属性的分析:网上的文章都说得不太清楚 ...

  • iOS 导航栏、状态栏

    一、修改导航栏及状态栏的透明度 iOS 修改导航栏及状态栏的透明度 二、导航栏返回按钮靠右问题

  • iOS 获取状态栏、导航栏、tabBar高度

    状态栏、导航栏 和 tabbar 高度(pt) iPhone型号 状态栏 状态栏 导航栏 导航栏 tabBa...

  • Android隐藏状态栏、导航栏

    Android隐藏状态栏、导航栏 Android 动态隐藏显示导航栏,状态栏 一、导航栏: 相关: 二、状态栏: ...

  • Android状态栏总结

    参考:android沉浸式状态栏、fitsSystemWindows、标题栏折叠 android中的windowT...

  • AS

    预留顶部状态栏 android:fitsSystemWindows="true" 跑java错误 CreateP...

  • iOS 宏定义-获取状态栏、导航栏、tabBar高度

    iOS 宏定义-获取状态栏、导航栏、tabBar高度 获取状态栏、导航栏、tabBar高度 //获取状态栏的高度C...

  • fitsSystemWindows之大坑

    fitsSystemWindows通常我们用来实现各版本来状态栏的适配(API19以上我们才能修改状态栏),但在使...

  • NavigationBar

    setTranslucent ios 7 之后,setTranslucent=yes 默认的 则状态栏及导航栏底...

  • iOS状态栏使用总结<转>

    目录: 一、状态栏与导航栏二、设置状态栏显隐与字体样式三、设置状态栏背景色四、启动页隐藏状态栏五、状态栏、导航栏相...

网友评论

    本文标题:状态栏及导航栏 fitsSystemWindows

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