android 沉浸式状态栏-4.4版本qq
来源:互联网 发布:以上内容来源于网络 编辑:程序博客网 时间:2024/05/24 06:56
1. 前言
沉浸式模式(Immersive Mode)大家应该都非常熟悉了,其实说白了,就是全屏显示。类似qq的界面如图所示:
注意:这个特性是andorid4.4支持的,最少要api19才可以使用.
2.使用方法
仅仅只需要几行代码就能完全实现沉浸式模式:
(1)activity中添加如下代码:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (Build.VERSION.SDK_INT >= 19) { //透明状态栏 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); //透明导航栏 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } }
(2)xml文件中加入如下代码:
android:fitsSystemWindows="true" android:clipToPadding="true"
这段代码有两个作用:1.解决文字和状态栏重叠在一起。2.决定状态栏颜色
(3)状态栏颜色
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#123456" android:orientation="vertical" android:fitsSystemWindows="true" android:clipToPadding="true" tools:context="com.example.test.test.MainActivity"> <TextView android:text="Hello World!" android:background="#666666" android:layout_width="wrap_content" android:layout_height="100dp" /> <TextView android:text="Hello World!" android:background="#987654" android:layout_width="wrap_content" android:layout_height="100dp" /></LinearLayout>
状态栏将和背景一个颜色,如下图所示:
把那两行代码放到我们顶部的控件就可以实现状态栏颜色跟顶部控件颜色一致,如图所示:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#123456" android:orientation="vertical" tools:context="com.example.test.test.MainActivity"> <TextView android:fitsSystemWindows="true" android:clipToPadding="true" android:text="Hello World!" android:background="#666666" android:layout_width="match_parent" android:layout_height="100dp" /> <TextView android:text="Hello World!" android:background="#987654" android:layout_width="match_parent" android:layout_height="100dp" /></LinearLayout>
3.一些坑
(1)状态栏背景色
上面的FLAG_TRANSLUCENT_STATUS 只是把状态栏设置为透明的,但是,状态栏是有背景色的,一些手机的状态栏背景色为透明,而一些手机的状态栏背景色为半透明的黑色.于是在5.0上增加了WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS 和 getWindow().setStatusBarColor(int color),在5.0才能看到清爽的全透状态栏。使用方法如下:
// 部分机型的statusbar会有半透明的黑色背景getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);getWindow().setStatusBarColor(Color.TRANSPARENT);// SDK21
(2)状态栏字体颜色
在6.0增加了View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR,这个字段就是把状态栏标记为浅色,然后状态栏的字体颜色自动转换为深色。所以,如果需要浅色的状态栏,只能在Android6.0及以后的版本中实现。
if (Build.VERSION.SDK_INT >= 23) { win.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//透明状态栏 // 状态栏字体设置为深色,SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 为SDK23增加 win.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); }
4.demo下载地址如下
demo下载地址
0 0
- android 沉浸式状态栏-4.4版本qq
- Android之4.4版本以上沉浸式状态栏实现
- Android沉浸式状态栏一体化最终版本
- Android沉浸式状态栏版本兼容问题
- android状态栏一体化、沉浸式状态栏(兼容低版本)
- android状态栏一体化、沉浸式状态栏(兼容低版本)
- android状态栏一体化、沉浸式状态栏(兼容低版本)
- android状态栏一体化、沉浸式状态栏(兼容低版本)
- android状态栏一体化、沉浸式状态栏(兼容低版本)
- Android沉浸式状态栏5.0版本及透明状态栏兼容4.4
- Android 之低版本高版本实现沉浸式状态栏
- android 4.4以后实现沉浸式状态栏 像最近Android QQ中实现的样式
- android 4.4状态栏沉浸
- Android 沉浸式状态栏
- android 沉浸式 状态栏
- android 沉浸式状态栏
- android沉浸式状态栏
- Android沉浸式状态栏
- 初识AudioTrack
- Apatch Tomcat8.0 的配置遇到问题解决
- caffe样例_R-CNN detection基于Ubuntu_Caffe
- Unity3D Shader 入门
- RxAndroid之Action,Func,map,flatmap的简单用法。
- android 沉浸式状态栏-4.4版本qq
- 使用Idea 16远程部署调试tomcat
- 最新MAC下SVN项目管理
- 【操作系统】C语言模拟操作系统实现磁盘调度算法——电梯调度算法
- ObObjective-C++环境配置
- libevent2.0源码学习二:通用数据结构
- Java之建造者模式(Builder Pattern)
- 从相机相册获取图片裁剪后用于评论晒图或更换背景图
- 地图投影知识系列(一)---世界地图投影