在4.4以上的手机上运行网易新闻和QQ都会出现java
与标题栏同色的通知栏android
设置方法有两种:布局
1.增长values-v19文件夹编写style.xml
ui
<style name="Theme.Timetodo" parent="@android:style/Theme.Holo.Light"> <!-- 透明状态栏 --> <item name="android:windowTranslucentStatus">true</item> <!-- 透明导航栏 --> <item name="android:windowTranslucentNavigation">true</item> </style>
在manifest.xml中引用该stylethis
2.在Activity的onCreate中.net
if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { // 透明状态栏 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // 透明导航栏 getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); }
上面的两个方法状态栏颜色能够在布局的根目录设置颜色。code
3.下载http://www.oschina.net/code/snippet_2406628_51101
xml
主页中增长代码图片
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); // 使用颜色资源 tintManager.setStatusBarTintResource(R.color.title_bg); // 使用图片资源 // tintManager.setStatusBarTintDrawable(getResources().getDrawable(R.drawable.ic_top_title_background)); }
最后在布局文件中的根控件中使用android:fitsSystemWindows="true"不然整个整个布局会和状态栏有重叠ip