沉浸式状态栏
来源:互联网 发布:数据库工程师 编辑:程序博客网 时间:2024/05/12 18:22
- 适配android5.x
<style name="AppTheme.Base"parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/colorPrimary</item> <!-- colorPrimary is used for the action bar --> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <!-- colorPrimaryDark is used for the status bar --> <item name="colorAccent">@color/colorAccent</item> <!-- colorAccent is used as the default value for colorControlActivated which is used to tint widgets --> <item name="android:windowAnimationStyle">@style/ActivityAnim</item> </style> <style name="AppTheme" parent="AppTheme.Base"></style>
//具体设置某个页面
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ getWindow().setStatusBarColor(getResources().getColor(R.color.red));}
注意事项:
<1>对于5.0由于提供了setStatusBarColor去设置状态栏颜色,但是这个方法不能在主题中设置windowTranslucentStatus属性。
2.适配4.4 &状态栏可利用(状态栏透明化&可利用 从此版本开始)
在适配5.x的基础上添加如下:
在activity
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);}
如果采用values-v19 则部分手机会不适用
<style name="AppTheme" parent="AppTheme.Base"> <item name="android:windowTranslucentStatus">true</item> </style>
如此则造成top挤压status bar 解决方法如下:
方案一:在程序中动态设置topview 的padding
frag_community_top.setPadding(0, CommonUtils.getStatusBarHeight(getActivity()),0,0);
方案二:
<2>在layout_top 布局中添加
android:fitsSystemWindows="true"
注意:
1、android:fitsSystemWindows="true"
这个一个boolean值的内部属性,让view可以根据系统窗口(如status bar)来调整自己的布局,如果值为true,就会调整view的paingding属性来给system windows留出空间….
2、如果是在viewpager +fragment 中使用 则会出现 第一个加载的fragment正常 ,之后的布局还是会挤压状态栏
解决方案1:
activity中:使用android:fitsSystemWindows
fragment中:使用 if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT){
frag_community_top.setPadding(0, ToolsUtil.getStatusBarHeight(getActivity()),0,0);
}
解决方案2:
都使用 if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT){
frag_community_top.setPadding(0, ToolsUtil.getStatusBarHeight(getActivity()),0,0);
}
- 状态栏、沉浸式状态栏
- 沉浸式状态栏/透明状态栏
- 透明状态栏(沉浸式状态栏)
- Android 沉浸式状态栏
- 沉浸式状态栏
- android 沉浸式 状态栏
- android 沉浸式状态栏
- android沉浸式状态栏
- 沉浸式状态栏
- Android沉浸式状态栏
- Android 沉浸式状态栏
- 沉浸式状态栏
- 沉浸式状态栏
- android 沉浸式状态栏
- Android沉浸式状态栏
- 设置沉浸式状态栏
- Android沉浸式状态栏
- 沉浸式状态栏
- Linux字符设备驱动结构
- ios时间戳与时间的转换
- 心情日记
- Thrift的学习
- #李白诗作的主要内容#
- 沉浸式状态栏
- LeetCode 059 Spiral Matrix II
- 1.2 Python的特点
- 第三方登录和分享
- 【2016 Esri 全球用户大会主题看点】3D
- Android如何减少压缩包的体积
- Web GIS离线解决方案
- IE网页贴纸打印程序
- 纯css实现箭头,上下左右的箭头