原文链接:http://www.bkjia.com/Androidjc/913061.html

  • 第一种方法

这里写代码片第一种方法,在代码设置:

if(VERSION.SDK_INT >= VERSION_CODES.KITKAT) {

//透明状态栏

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

//透明导航栏

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

}

直接调用上面2行代码可以透明,但是你会发现你的 view 跑到 actionbar 上面去了,很明显 google 的意图是使你的 view 可以占据整个屏幕,然后 状态栏和导航栏 透明覆盖在上面很明显这样不可行。

那有没有办法使你的 view 保持原来大小呢?

有,你需要在这个 activity 的 layout xml 文件添加两个属性

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal" android:fitsSystemWindows="true"
android:clipToPadding="true" android:orientation="vertical" >
  • 第二种方法

    第二种方式,是设置 theme 属性

android:theme=”@android:style/Theme.DeviceDefault.Light.NoActionBar.TranslucentDecor”

android:theme=”@android:style/Theme.Holo.Light.NoActionBar.TranslucentDecor”

android:theme=”@android:style/Theme.Holo.NoActionBar.TranslucentDecor”

复制代码 如果你使用自定主题,只需在在 values-19 文件添加以下属性:

<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">

        <!-- API 19 theme customizations can go here. -->
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>

刚刚说了这个使用有局限性,不过好在有一个开源的东西

https://github.com/jgilfelt/SystemBarTint

使用这个开源库,必须开启透明标题栏

最新文章

  1. c++编译错误提示及解决
  2. gson使用注意事项
  3. Ajax条用WebService 5星级
  4. 【规范】javascript 变量命名规则(转)
  5. [ReactJS] DOM Event Listeners in a React Component
  6. java 二维码原理以及用java实现的二维码的生成、解码(转)
  7. [使用]Git--命令行
  8. GitHub常见错误解决办法
  9. 第二次冲刺spring会议(第五次会议)
  10. Struts2 控制文件上传下载
  11. PHPcms9.6.0任意文件上传漏洞直接getshell 利用教程
  12. oracle排序的几种方法
  13. oracle开启一个用户
  14. es6 遍历总结
  15. x509证书相关内容
  16. “由于下列错误,Parallel port driver 服务启动失败”,注意了
  17. f5双机配置
  18. Ngen.exe和本机映像缓存
  19. hdoj 1299 Diophantus of Alexandria
  20. Vuex内容解析和vue cli项目中使用状态管理模式Vuex

热门文章

  1. 基于puppet分布式集群管理公有云多租户的架构浅谈
  2. iOS逆向工程,(狗神)沙梓社大咖免费技术分享。
  3. 通过Navicat连接MySQL数据库
  4. HTTP请求过程-域名解析和TCP三次握手建立链接
  5. jQuery中append appendTo prepend prependTo insertBefore insertAfter after before之间的区别
  6. Mysql 忘记管理员密码更改
  7. kubernetes Auto Install Guide
  8. Openstack Pycharm 的远程调试
  9. mybatis-spring整合
  10. The Problems of Mysql Installation