沉浸式状态栏(SystemBarTint)的实现以及在线导入External Libraries
来源:互联网 发布:淘宝助理5.5版本下载 编辑:程序博客网 时间:2024/06/11 04:31
什么是沉浸式状态栏看一下效果:
如图,为状态栏设置背景颜色即为沉浸式状态栏,是Android4.4以上的特性。
1, 要实现沉浸式状态栏首先在线导入systembartint-1.0.4
右击module -> Open Moudle Settings ->Dependencies -> ‘+’号->Library dependency
搜索systembartint:
搜索结果:
添加点击ok
2,源码实现
1)布局
<?xml version="1.0" encoding="utf-8"?><RelativeLayout 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:fitsSystemWindows ="true" android:clipToPadding="false" tools:context="jiandai.jiandai.com.systembartint.MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="HelloWorld!"/></RelativeLayout>
注意,这里加上了两行代码
android:fitsSystemWindows ="true"android:clipToPadding="false"
上面的第一行代码fitsSystemWindows的作用是:
让view可以根据系统窗口(如status bar)来调整自己的布局,如果值为true,就会调整view的paingding属性来给system windows留出空间。
第二行代码clipToPadding 值控件的绘制区域是否在padding里面的,默认是true,设置成false就表示可已在控件外面显示。
2) activity代码:
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4以上版本 setTranslucentStatus(true); } SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true);//开启状态栏 tintManager.setNavigationBarTintEnabled(true);//导航栏染色 tintManager.setTintColor(Color.parseColor("#E84217"));//自定义颜色 } 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); }}
重点说一下setTranslucentStatus方法,首先得到我们应用的窗口布局,如果设置了显示状态栏染色的话,窗口的flag就会设置成FLAG_TRANSLUCENT_STATUS,应用所占的屏幕会扩大到全屏,这样的话,就必须让内容向下错出一个状态栏的高度。
效果:
1 0
- 沉浸式状态栏(SystemBarTint)的实现以及在线导入External Libraries
- 沉浸式状态栏实现-SystemBarTint
- SystemBarTint实现沉浸式状态栏
- SystemBarTint沉浸式状态栏
- Android沉浸式状态栏SystemBarTint的使用方法
- Android沉浸式状态栏SystemBarTint的使用方法
- Android沉浸式状态栏SystemBarTint的使用方法
- Android沉浸式状态栏SystemBarTint的使用方法
- 沉浸式状态栏框架-SystemBarTint
- Android沉浸式状态栏SystemBarTint
- Android使用systembartint库实现沉浸式状态栏效果
- Android 实现沉浸式状态栏效果(systembartint库)
- 沉浸式状态栏的设定-com.readystatesoftware.systembartint:systembartint 的使用
- 基于SystemBarTint快速打造沉浸式状态栏
- Android沉浸式通知栏的一个开源库SystemBarTint简单使用,android沉浸式状态栏
- 借助SystemBarTint实现透明标题栏(沉浸式)
- SystemBarTint实现沉浸模式
- Android 沉浸式状态栏实现,以及遇到的问题
- Liblinphone 3.9.1中文--Modules--Managing Buddies and buddy list and presence
- java Exception 出错的栈信息打印到日志中 打印堆栈信息
- 缘起普洱茶.....感恩
- VS2010/MFC编程入门之三十六(工具栏:工具栏资源及CToolBar类)
- 最佳的学习时间是十年前,下一个是现在
- 沉浸式状态栏(SystemBarTint)的实现以及在线导入External Libraries
- Spring注解@Component、@Repository、@Service、@Controller区别
- 909422229__JavaScript数值转换的三种方式总结
- word2vect实战
- 基于物理着色
- Glide获取bitmap
- Uncaught ReferenceError: Ext is not defined
- VS2010/MFC编程入门之三十七(工具栏:工具栏的创建、停靠与使用)
- 回车(CR)与换行(LF), '\r'和'\n'的区别