Step1:状态栏与导航栏半透明化

  • 方法一:继承主题特定主题

    在Android API 19以上可以使用*.TranslucentDecor有关的主题,自带相应半透明效果

    例如:
<style name="FullBleedTheme" parent="android:Theme.Holo.Light.NoActionBar.TranslucentDecor">
<!-- API 19 theme customizations can go here. -->
</style>
  • 方法二:自定义主题中使用一下设置
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
<item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>
  • 方法三:在Activity中设置布局文件之后调用这些代码实现
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = getWindow();
// Translucent status bar
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// Translucent navigation bar
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}

SystemBarTint作者提供的变形方法如下

@TargetApi(19)
private void setTranslucentStatus(boolean on) {
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
if (on) {
winParams.flags |= bits;
} else {
winParams.flags &= ~bits;
}
win.setAttributes(winParams);
}

Step2:此时状态栏占有的位置消失,方法同样有三

  • 方法一:需要在布局文件根布局中添加一下代码
android:fitsSystemWindows="true"
  • 方法二:在主题中设置如下:
<item name="android:fitsSystemWindows">true</item>
  • 方法三:使用Java代码:
rootview.setFitsSystemWindows(true);

Step3:设定状态栏和导航栏背景色

这时候状态栏半透明,显示的颜色根据根布局的背景颜色而来,由此可以给根布局背景色位所需的颜色即可。

但是这样会给根布局的子布局控件的背景设置带来不便。

所以采用SystemBarTint实现沉浸式状态栏

方法如下:

SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setNavigationBarTintEnabled(true);
tintManager.setTintColor(ContextCompat.getColor(this, R.color.colorPrimary));

几个问题

  • 使用SystemBarTint不能给状态栏设置多个颜色,不能自动取色?
  • Android5.0(API 21)之后ActionBar主题中几个颜色代表的意义
  <style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/accent</item>
</style>

参考资料

Android沉浸式状态栏实现的更多相关文章

  1. Android 沉浸式状态栏 实现方式二 ( 更简单 )

    以前写过一个沉浸式状态栏 的实现方式 Android 沉浸式状态栏 实现方式一 现在有个更为简单的实现方式 . 相关链接 http://www.apkbus.com/forum.php?mod=vie ...

  2. android 沉浸式状态栏的实现

    本文介绍一种简单的实现沉浸式状态栏的方法,要高于或等于api19才可以. 实现android沉浸式状态栏很简单,添加代码两步就可以搞定. 一.在activity中添加 getWindow().addF ...

  3. [置顶] Xamarin android沉浸式状态栏

    虽然关于android "沉浸式"状态栏有很多博客介绍过,从小菜到大神无一例外.我第一次看到这种"沉浸"式的效果我也以为真的是这么叫,然而根本不是这么回事,完全 ...

  4. Android 沉浸式状态栏完美解决方案

    现在搜索Android 沉浸式状态栏,真的是一堆一堆,写的特别多,但是真正用的舒服的真没有,在这里自己整理一下开发记录 注意,在使用这个步骤过程之前,请把之前设置的代码注释一下 把布局带有androi ...

  5. Android沉浸式状态栏(透明状态栏)最佳实现

    Android沉浸式状态栏(透明状态栏)最佳实现 在Android4.4之前,我们的应用没法改变手机的状态栏颜色,当我们打开应用时,会出现上图中左侧的画面,在屏幕的顶部有一条黑色的状态栏,和应用的风格 ...

  6. 【Android实战】Android沉浸式状态栏实现(下)

    之前的Android沉浸式状态栏实现并没有考虑软键盘的影响,接下来的内容将会针对这个问题给出解决方式,先看一下效果图 这个是一个留言板的效果图: 即弹出软键盘的时候并不会导致整个布局上移. 详细怎样实 ...

  7. android沉浸式状态栏设置(4.4以上版本)

    其实设置比较简单,我用了小米和htc的几款机型都可以用. 主要代码就是这个(注意要在Activity的setContentView之前调用才行) /** * 开启沉浸式状态栏 * */ public ...

  8. Android 沉浸式状态栏

    1,传统的手机状态栏是呈现出黑色或者白色条状的,有的和手机主界面有很明显的区别.这样就在一定程度上牺牲了视觉宽度,界面面积变小.看一下QQ的应用 2,实现起来也挺简单的,来一起看一下吧 MainAct ...

  9. Android 沉浸式状态栏攻略 让你的状态栏变色吧

    转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/48649563: 本文出自:[张鸿洋的博客] 一.概述 近期注意到QQ新版使用了 ...

随机推荐

  1. leetcode@ [49] Group Anagrams (Hashtable)

    https://leetcode.com/problems/anagrams/ Given an array of strings, group anagrams together. For exam ...

  2. Mongodb 和 普通数据库 各种属性 和语句 的对应

    SQL to MongoDB Mapping Chart In addition to the charts that follow, you might want to consider the F ...

  3. Linux Pmap 命令:查看进程用了多少内存

    Pmap 提供了进程的内存映射,pmap命令用于显示一个或多个进程的内存状态.其报告进程的地址空间和内存状态信息.Pmap实际上是一个Sun OS上的命令,linux仅支持其有限的功能.但是它还是对查 ...

  4. SQLite数据库入门教程

    SQLite数据库入门教程 SQLite 是一个开源的嵌入式关系数据库,实现自包容.零配置.支持事务的SQL数据库引擎. 其特点是高度便携.使用方便.结构紧凑.高效.可靠. 与其他数据库管理系统不同, ...

  5. Spring ApplicationContextAware获取上下文

    一.ApplicationContextAware 用处 Spring 提供了ApplicationContextAware类,通过它可以获取所有bean上下文. 二.怎么用? ①.定义一个工具类,去 ...

  6. Android下得到已安装Application信息

    在上一篇blog中,谈到如何利用APK archive文件得到相应信息.(当时发现例如ProcessName,DataDir等信息,其实是无法得到的). 当前咱们看看如何通过系统取得已经安装的Appl ...

  7. [GIF] Parenting in GIF Loop Coder

    In this lesson, we look at how you can build up complex animations by assigning one shape as the par ...

  8. Lazy Load 图片延迟加载(转)

    jQuery Lazy Load 图片延迟加载来源 基于 jQuery 的图片延迟加载插件,在用户滚动页面到图片之后才进行加载. 对于有较多的图片的网页,使用图片延迟加载,能有效的提高页面加载速度. ...

  9. div 显示滚动条的CSS代码

    div 显示滚动条的CSS代码   div显示上下左右滚动条 <div style="width:260px;height:120px; overflow:scroll; border ...

  10. OpenCMS integration with Spring MVC--reference

    ref from:http://blogs.indrajitpingale.com/?p=8 http://blog.shinetech.com/2013/04/09/integrating-spri ...