android的透明顶栏是在android5.0加入的新特性, 虽然其实在ios中早就有了.....:在5.0中的实现方式很简单:
在style. 中的application 的主题中添加colorPrimary,即可, 还可以设置更多的默认颜色来进行主题的搭配,当然这不是我今天要说的重点;
为了在android4.4及以上的设备上也有沉浸式的体验,其实我们只要加入下面的代码在Activity的OnCreat中就可以了:
public static void setTransparentStyle(Context context, int colorResourceID){ //获取颜色 int color = context.getResources().getColor(colorResourceID); //形成完整沉浸式的方法 ((Activity)context).getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); SystemBarTintManager tintManager = new SystemBarTintManager((Activity) context); tintManager.setStatusBarTintEnabled(true); // 设置一个颜色给系统栏 tintManager.setTintColor(color); // 设置一个状态栏资源 tintManager.setStatusBarTintColor(color); }这段代码有一个依赖的类, 直接复制到自己的工程中引用即可:
< src="https://code.csdn.net/snippets/984384.js"></ >
继续阅读与本文标签相同的文章
下一篇 :
Meta-data的作用和自定义
-
C# 使用MarshalByRefObject跨程序调用方法
2026-06-02栏目: 教程
-
PDB文件:每个开发人员都必须知道的
2026-06-02栏目: 教程
-
远程桌面使用方法
2026-06-02栏目: 教程
-
数据库设计(Database Design)
2026-06-02栏目: 教程
-
node.js爬虫应用——前端程序员的词典command-translator
2026-06-02栏目: 教程
