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{
//低版本 直接设置0
statusBarHeight = 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());
}
} @Override
protected 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 沉浸式状态栏的实现

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

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

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

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

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

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

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

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

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

  7. Android沉浸式状态栏实现

    Step1:状态栏与导航栏半透明化 方法一:继承主题特定主题 在Android API 19以上可以使用****.TranslucentDecor***有关的主题,自带相应半透明效果 例如: < ...

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

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

  9. Android沉浸式状态栏兼容4.4手机的实现

    一.概述 最近注意到QQ新版使用了沉浸式状态栏,ok.先声明一下:本篇博客效果下图: 关于这个状态栏变色究竟叫「Immersive Mode」/「Translucent Bars」有兴趣能够去 为什么 ...

  10. Android 沉浸式状态栏的三种实现方式

    沉浸式状态栏 Google从android kitkat(Android 4.4)開始,给我们开发人员提供了一套能透明的系统ui样式给状态栏和导航栏,这种话就不用向曾经那样每天面对着黑乎乎的上下两条黑 ...

随机推荐

  1. 车辆运动控制算法——MPC

    MPC是模型预测控制算法,在车辆运动跟踪轨迹的控制中发挥很大的优势 基础的不多说,下面记录我对LQR/MPC/二次规划问题的理解 我们从LQR来引出MPC LQR的能量函数,目的是求函数J最小,即用最 ...

  2. 前端基础:”天龙八步“细说浏览器输入URL后发生了什么

    参考:https://www.xuecaijie.com/it/157.html#1Q64p5DeC8dKFF 本文摘要: 1.DNS域名解析: 2.建立TCP连接: 3.发送HTTP请求: 4.服务 ...

  3. 09 . Prometheus监控tomcat+jvm

    List CentOS7.3 prometheus-2.2.1.linux-amd64.tar.gz redis_exporter-v0.30.0.linux-amd64.tar.gz 节点名 IP ...

  4. how to switch a different buffer from a terminal buffer

    In term-mode, any regular C-x whatever keybinding becomes C-c whatever instead.

  5. 一个ACE 架构的 C++ Timer

    .h #ifndef _Timer_Task_ #define _Timer_Task_ #pragma once #include <ace/Task.h> #include <a ...

  6. (私人收藏)红色项目工作计划总结汇报PPT模板

    红色项目工作计划总结汇报PPT模板 https://pan.baidu.com/s/1fr-PB7ieveSIqSXrB0YXsgbgdc

  7. Tomcat Filter之动态注入

    前言 最近,看到好多不错的关于"无文件Webshell"的文章,对其中利用上下文动态的注入Filter的技术做了一下简单验证,写一下测试总结,不依赖任何框架,仅想学习一下tomca ...

  8. html实现时间轴_纯css实现响应式竖着/垂直时间抽布局效果

    1.概述 html实现用时间点来展示事件发生点来代替用table展示一条条数据,能够给人清晰.一目了然能够看清事情发生的过程,UI页面也显示的那么清晰.如何用css+html做出时间轴展示事件点的?先 ...

  9. css文字不透明度怎么设置?

    在css中有很多好看的样式都可以实现,css设置出来的样式让整个网页看起来也会非常美观,今天的这篇文章就给大家来介绍一下在css中怎么设置文字的透明度,让你的文字在网页中看起来是透明的. CSS设置透 ...

  10. 我打算用JAVA实现GB/T32960 监控平台的tcp server

    之前是用golang写得 ,因为对golang不是很熟练,打算基于netty再写一个,开源出来. 如果近期时间宽裕,就准备着手了. 有兴趣的朋友也可以留言一起做.