透明状态栏
2015-06-30 13:22
211 查看
private boolean isLmpOrAbove() {
return Build.VERSION.SDK_INT >= 21;//Build.VERSION_CODES.LOLLIPOP;
}
//状态栏透明
@TargetApi(19)
private void setupTransparentSystemBarsForLmp() {
// TODO(sansid): use the APIs directly when compiling against L sdk.
// Currently we use reflection to access the flags and the API to set
// the transparency
// on the System bars.
if (isLmpOrAbove()) {
try {
getWindow().getAttributes().systemUiVisibility |= (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField("FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
Method setStatusBarColorMethod = Window.class.getDeclaredMethod("setStatusBarColor", int.class);
Method setNavigationBarColorMethod = Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
} catch (NoSuchFieldException e) {
Log.w("yfl", "NoSuchFieldException while setting up transparent bars");
} catch (NoSuchMethodException ex) {
Log.w("yfl", "NoSuchMethodException while setting up transparent bars");
} catch (IllegalAccessException e) {
Log.w("yfl", "IllegalAccessException while setting up transparent bars");
} catch (IllegalArgumentException e) {
Log.w("yfl", "IllegalArgumentException while setting up transparent bars");
} catch (InvocationTargetException e) {
Log.w("yfl", "InvocationTargetException while setting up transparent bars");
} finally {
}
}
}
return Build.VERSION.SDK_INT >= 21;//Build.VERSION_CODES.LOLLIPOP;
}
//状态栏透明
@TargetApi(19)
private void setupTransparentSystemBarsForLmp() {
// TODO(sansid): use the APIs directly when compiling against L sdk.
// Currently we use reflection to access the flags and the API to set
// the transparency
// on the System bars.
if (isLmpOrAbove()) {
try {
getWindow().getAttributes().systemUiVisibility |= (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField("FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
Method setStatusBarColorMethod = Window.class.getDeclaredMethod("setStatusBarColor", int.class);
Method setNavigationBarColorMethod = Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
} catch (NoSuchFieldException e) {
Log.w("yfl", "NoSuchFieldException while setting up transparent bars");
} catch (NoSuchMethodException ex) {
Log.w("yfl", "NoSuchMethodException while setting up transparent bars");
} catch (IllegalAccessException e) {
Log.w("yfl", "IllegalAccessException while setting up transparent bars");
} catch (IllegalArgumentException e) {
Log.w("yfl", "IllegalArgumentException while setting up transparent bars");
} catch (InvocationTargetException e) {
Log.w("yfl", "InvocationTargetException while setting up transparent bars");
} finally {
}
}
}
相关文章推荐
- spring源码初步学习-自己实现的ioc容器结构
- solr4.7中文分词器(ik-analyzer)配置
- 04 基本元素 进制转换
- Xcode的控制台调试命令
- delphi 截图简单的实现
- 使用AudioTrack进行音频播放
- python
- hdu2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
- PL/SQL8.0 注册码
- 涨停板联盟7月1日分享。
- device_create,device_create_file
- RedHat下更新gcc编译器
- Android-基础笔记-HTTP (一)
- android5.0远程绑定service
- 12. Magento 后台top栏开发
- 110.按照规定删除字符串前导星号
- Django开发(二)——后台管理模块
- MFC,C++ 截屏
- 系统吞吐量、TPS(QPS)、用户并发量、性能测试概念和公式
- Apache+tomcat或Nginx+tomcat集群搭建