设置沉浸式状态栏
2016-02-27 10:24
543 查看
在Android4.4之后推出了沉浸式状态栏,那么怎么使用它呢?下面我来讲解:
1、实现原理
沉浸式状态栏是在Google在4.4系统出来之后推出的,也就是说只能在4.4系统之上使用这个特性首先,我们要明白的是Activity的底层的布局是什么,是DecorView,也就是只要我们改变底层的DecorView的状态栏的背景就可以了。
2、实现方法
这里介绍一个GitHub上的开源库,用来实现改变的StatusBar的背景。
项目地址:SystemBarTint
具体的可以参考项目介绍。
3、具体的实现方法
(1)代码设置
(2)布局设置
1、实现原理
沉浸式状态栏是在Google在4.4系统出来之后推出的,也就是说只能在4.4系统之上使用这个特性首先,我们要明白的是Activity的底层的布局是什么,是DecorView,也就是只要我们改变底层的DecorView的状态栏的背景就可以了。
2、实现方法
这里介绍一个GitHub上的开源库,用来实现改变的StatusBar的背景。
项目地址:SystemBarTint
具体的可以参考项目介绍。
3、具体的实现方法
(1)代码设置
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //首先检测当前的版本是否是api>=19的 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); } SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintColor(Color.parseColor("#FFC1E0")); } @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); } }
(2)布局设置
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" <!--这两行是必须设置的--> android:fitsSystemWindows="true" android:clipToPadding="true" android:orientation="vertical" android:background="#FFD9EC" > <TextView android:text="沉浸式状态栏" android:layout_width="match_parent" android:layout_height="50dp" android:textSize="23dp" android:layout_gravity="center_horizontal" android:gravity="center" android:background="#FFD9EC" /> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/darker_gray"/> </LinearLayout>
相关文章推荐
- android创建SQlite数据库和表格详解
- [Locked] Binary Tree Vertical Order Traversal
- 分布式技术一周技术动态 2016.02.28
- BZOJ1565 植物大战僵尸
- apache AH00558 错误的解决
- 开机出现指令“Ox00000000”的内存,该内容不能为read解决方法
- 2016-2小笔记
- 视频播放器
- 微型投影仪:MSP430
- IP电话知识点与协议
- Java Sax解析xml
- 如何清除远程桌面连接的IP域名信息
- not in子查询的用法
- c++ virtual
- C语言书籍推荐
- H264编码原理以及I帧B帧P帧
- js 提示对话框知识
- (一)图像坐标:我想和世界坐标谈谈(A) 【计算机视觉学习笔记--双目视觉几何框架系列】
- ASP.NET 页面之间传递值的几种方式
- Linux如何查看JDK的安装路径