改变状态栏颜色
来源:互联网 发布:mac app store下载慢 编辑:程序博客网 时间:2024/05/16 08:15
这样的效果:
方法一.使用SystemBarTintManager :
在需要改变状态栏颜色的Activity中加入代码:
//只对API19以上版本有效 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); } //为状态栏着色 SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintResource(R.color.statusbar);
@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); }
方法二:
1.先在values文件夹下的styles.xml 文件中设置如下主题:
<!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> <!--在Android 4.4之前的版本上运行,直接跟随系统主题--> <style name="TranslucentTheme" parent="AppTheme"> </style>
2.在values-19中添加styles:
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">false</item> </style>
3.在values-21中添加styles:
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">false</item> <item name="android:statusBarColor">@android:color/transparent</item> </style>
4.在相应的activity中添加AppTheme:
android:theme="@style/AppTheme"
5.在xml文件最外层布局中添加:
android:fitsSystemWindows="true"
这样的效果:
在Activity中添加:
View decorView = getWindow().getDecorView(); int option = View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(option); ActionBar actionBar = getSupportActionBar(); actionBar.hide();
这样的效果(5.0以上):
if (Build.VERSION.SDK_INT >= 21) { View decorView = getWindow().getDecorView(); int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; decorView.setSystemUiVisibility(option); getWindow().setStatusBarColor(Color.TRANSPARENT); } ActionBar actionBar = getSupportActionBar(); actionBar.hide(); }
0 0
- 改变系统状态栏颜色
- 改变状态栏的颜色
- 改变状态栏的颜色
- 改变状态栏颜色
- Android_改变状态栏颜色
- 改变状态栏颜色
- 改变状态栏字体颜色
- 改变状态栏字体颜色
- 改变状态栏背景颜色
- 改变状态栏背景颜色
- android 状态栏颜色改变
- 改变状态栏颜色
- Android 改变状态栏颜色
- Xcode8改变状态栏颜色
- 改变状态栏的颜色
- 状态栏字体颜色改变
- 改变android状态栏颜色
- 顶部状态栏改变颜色
- iOS中的单例模式
- 南方谷铺的五大优势!
- parse server搭建
- 标准库bitset
- iOS--UIWebView 屏蔽 alert警告框
- 改变状态栏颜色
- LinkedList源码解析
- solr安装
- 移动端qq浏览器a标签不显示的问题
- extjs树形下拉框
- hashSet详解
- 迭代器
- RMI、RPC、SOAP通信技术对比
- Swift-枚举关联值以及提取