Android标题栏沉浸效果
来源:互联网 发布:联合舰队 知乎 编辑:程序博客网 时间:2024/05/18 16:57
android标题栏沉浸效果
android4.4开始实现了状态栏的沉浸,即状态栏一体化,效果如图:
下面来看实现步骤:
首先,你需要在value-19中的style.xml中添加以下属性:
<style name="AppTheme" parent="@style/AppBaseTheme"> <item name="android:windowTranslucentStatus">true</item> </style>
然后在AnroidManifest.xml中application标签中添加android:theme=”@style/AppTheme”即可,这样你就可以在android4.4以上的系统中运行就会出现上图的效果,但是你会发现你的布局会与状态栏重叠,这样就会导致状态栏会遮挡,解决这种问题只需要在你的activity的布局文件中添加android:fitsSystemWindows=”true”属性,如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/default_color" android:fitsSystemWindows="true">
这样就可以避免状态栏的遮挡,在测试中发现,当运行在android4.4以下的系统上时,会发现会多出actionbar,解决这个问题也很简单,只需要在values文件夹下的style.xml中添加name=”android:windowNoTitle”>true即可,如下:
<!-- Application theme. --> <style name="AppTheme" parent="BaseAppTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> <item name="android:windowNoTitle">true</item> </style>
或者直接设置parent为一个带有windowNoTitle的theme,例如parent=”Theme.AppCompat.Light.NoActionBar”
另外,除了以上修改style.xml的方法之后,也可以在activity中直接实现,代码如下:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window window = getWindow(); // Translucent status bar window.setFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);}
至此,状态栏的沉浸就完成了,在开发中可能有一些要求,比如状态栏的颜色要比应用的主题的颜色要深一些等,这种问题有不同的解决办法,这里就不说了。另外,在测试中发现,在不同的系统上状态栏的沉浸效果还是不一样的,比如说6.0系统的状态栏要比背景颜色深很多,而5.0,4.4的系统状态栏与背景颜色就基本上相同,具体不同的系统所表现的不同的表现并没有做过多测试。
- Android标题栏沉浸效果
- android沉浸式标题栏
- Android 沉浸式标题栏
- Android仿百度外卖APP首页状态/标题栏效果(沉浸式状态栏)
- android 沉浸式效果
- android状态栏标题栏的沉浸式模式
- Android 标题栏沉浸式的实现
- android沉浸式状态栏、fitsSystemWindows、标题栏折叠
- Android标题栏显示效果
- Android沉浸式效果实现
- android使状态栏沉浸效果
- Android 状态栏沉浸式效果
- android标题栏滑动渐变效果
- Android 安卓 自定义标题栏+沉浸式状态栏
- Android沉浸式(侵入式)标题栏(状态栏)Status(一)
- Android沉浸式(侵入式)标题栏(状态栏)Status(二)
- Android沉浸式(侵入式)标题栏(状态栏)Status(三)
- Android沉浸式标题栏迄今为止最完美的解决方案
- NJUST5167 Fibonacci
- Linux下搭建Android开发环境及Android真机调试
- 最大子数组
- crontab scp 无法自动执行,公钥已经生成,手动可执行scp
- iOS动画篇:UIView动画
- Android标题栏沉浸效果
- ios中关于view的tag值的问题
- dblink2
- id to load is required for loading
- CentOS 7.x 下配置 DHCP 服务器 基础篇
- webView中获取response头部信息
- 柴俊理金:EIA首降原油暴涨,美指回落黄金企稳
- 69-Contains Duplicate
- dblink3