1. 在Activity的onCreate()方法中添加代码
//设置状态栏透明
StatusBarUtil.setTranslucentStatus(this);
//设置透明状态栏的paddingTop为false
setRootViewFitsSystemWindows(this,false);

在使用中经常会遇到图标和标题栏重叠的情况,可以使用StatusBarHeightView这个控件填充状态栏上方的位置

package com.onepilltest.util;import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.LinearLayout;import com.onepilltest.R;public class StatusBarHeightView extends LinearLayout {private int statusBarHeight;private int type;public StatusBarHeightView(Context context, @Nullable AttributeSet attrs) {super(context, attrs);init(attrs);}public StatusBarHeightView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init(attrs);}public StatusBarHeightView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {super(context, attrs, defStyleAttr);init(attrs);}private void init(@Nullable AttributeSet attrs) {int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {if(resourceId>0) {statusBarHeight = getResources().getDimensionPixelSize(resourceId);}}else{//低版本 直接设置0statusBarHeight = 0;}if (attrs != null) {TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.StatusBarHeightView);type = typedArray.getInt(R.styleable.StatusBarHeightView_use_type, 0);typedArray.recycle();}if (type == 1) {setPadding(getPaddingLeft(), statusBarHeight, getPaddingRight(), getPaddingBottom());}}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {if (type == 0) {setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),statusBarHeight);} else {super.onMeasure(widthMeasureSpec, heightMeasureSpec);}}
}

Android:沉浸式状态栏(二)集成相关推荐

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

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

  2. android 沉浸式开源库,Android沉浸式状态栏

    关于Android沉浸式状态栏, 网上已经有很多开源库, 虽然开源库可以解决某些特定布局下的沉浸式状态栏问题, 但是遇到比较特殊的布局就无法解决了, 所以了解一下沉浸式状态栏如何实现是有必要的. 无论 ...

  3. android沉浸式 字体,Android沉浸式状态栏背景色以及字体颜色的修改

    在activity中设置透明状态栏 的思路: 1.让activity的布局全屏 此时布局会和状态栏重叠 2.让布局最上方预留出和状态栏高度一样的高度,将状态栏的背景色设置为透明 效果如下: 一般是在s ...

  4. 使用主题Theme实现Android沉浸式状态栏

    使用主题Theme实现Android沉浸式状态栏 很早的时候,通过主题设置activity沉浸式,发现坑很多,就开始使用各种StatusBarUtils,放弃了主题修改沉浸式这种方式,不知道大家有没有 ...

  5. 高大上的Android沉浸式状态栏?

    背景 之前做过Android沉浸式状态栏的相关需求,但是一直忙于工作,没时间系统的整理下沉浸式相关的知识,所以今天抽出时间,写一篇 Android沉浸式状态栏的文章. 何为沉浸式 沉浸式就是要给用户提 ...

  6. android 5.0状态栏下载地址,Android沉浸式状态栏(5.0以上系统)

    Android沉浸式状态栏(5.0以上系统) 沉浸式状态栏可以分为两种: 1.直接给状态栏设置颜色 (如下图:) 这里写图片描述 java代码形式: if (Build.VERSION.SDK_INT ...

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

    Android 沉浸式状态栏完美解决方案 参考文章: (1)Android 沉浸式状态栏完美解决方案 (2)https://www.cnblogs.com/dingxiansen/p/9929828. ...

  8. Android沉浸式状态栏工具类,一句代码轻松搞定

    Android沉浸式状态栏工具类,一句代码轻松搞定 博客原文及源码地址:http://jaeger.itscoder.com/android/2016/03/27/statusbar-util.htm ...

  9. Android底部菜单栏、Android沉浸式状态栏(顶部状态栏修改颜色)、自定义标题栏

    0.简介: 没有使用TabHost切换,而是变成FragmentActivity替换Fragment:沉浸式引用的git上面的jar包. 先看图片 1.底部导航栏 核心代码 <span styl ...

  10. android 沉浸式状态栏 19,Android 沉浸式状态栏 以及 伪沉浸式状态栏

    小菜最近在调整页面状态栏的效果,主要包括沉浸式状态栏和伪沉浸状态栏(同事唠嗑给定义的玩的). 前段时间整理过一篇 Android 沉浸式状态栏的多种样式,现在小菜在稍微的补充一下,都是在日常应用中测试 ...

最新文章

  1. ​机器学习中必要的数学基础!
  2. JavaScript工具库之Lodash
  3. 快速排除故障命令除了ping还有tracert
  4. 曼哈顿距离java实现_基于javascript实现获取最短路径算法代码实例
  5. mysql 对象_查看MySQL中的对象
  6. 学长毕业日记 :本科毕业论文写成博士论文的神操作20170328
  7. 架构设计从这5点考虑,能帮后期运维很大忙!
  8. php简单环境,PHP 简单的环境搭建
  9. 多云平台_多云系统的授权
  10. 充分利用UC berkeleys数据科学专业
  11. 论文浅尝 | 基于对抗学习的弱监督知识图谱对齐
  12. 夏天面试男生穿什么_你今年夏天在做什么?
  13. delphi7下实现http的post_ASP.NET Core Web API 实现过程
  14. 世界备份日——如果您丢失了所有文件
  15. 美赛整理之带参数的常微分方程拟合问题研究
  16. 软件测试——测试分类及测试工具的简介
  17. win7共享计算机的用户名和密码,win7文件共享访问需要输入用户名和密码如何解决...
  18. “分类” 与 “回归”的概念及区别详解
  19. 为电商而生的知识图谱,如何感应用户需求? 1
  20. 动态拨号主机多IP随机分配拨号自动分配

热门文章

  1. 关于python中的round()和javascript中的round()的比较
  2. 如何用Chrome自带的截屏功能截取超过一个屏幕的网页 1
  3. Java多线程系列 面试题
  4. Unity工程中 .Meta 文件的来龙去脉
  5. linux 挂载硬件设备
  6. 《HTML5移动Web开发实战》—— 1.6 在移动网站中使用HTML5
  7. js方法实现rgb颜色转换成16进制格式的代码的方法
  8. 计算机专业和制药工程,制药工程本科专业介绍
  9. FireMonkey 源码学习(5)
  10. TYVJ1467 通往聚会的道路