经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 移动开发 » Android » 查看文章
Android 详解沉浸式状态栏的实现流程
来源:jb51  时间:2021/11/8 19:51:39  对本文有异议

Android—沉浸式状态栏

image

我们的征程是星辰大海,而非人间烟尘

去掉标题栏

首先去掉对应主题下面的Android自带的ActionBar,只需要在对应主题下面加NoActionBar

效果

引入依赖

  1. implementation 'com.jaeger.statusbarutil:library:1.5.1'

沉浸状态栏颜色

沉浸式状态栏,既可以把颜色实现沉浸,又可以把图片实现沉浸。

未设置颜色沉浸的状态:

image

逻辑代码:

  1. StatusBarUtil.setColor(MainActivity.this,getResources().getColor(R.color.teal_200),0)

image

布局文件

image

沉浸状态栏图片

未沉浸之前的效果

image

沉浸之后的效果

image

布局代码

  • 将要沉浸的图片放在ImageView组件里面
  • 其他的组件放在一个布局里面
  • 通过一个setTransparentForImageView方法替换

image

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context=".MainActivity">
  8.  
  9. <ImageView
  10. android:id="@+id/imageView"
  11. android:layout_width="0dp"
  12. android:layout_height="250dp"
  13. android:src="@drawable/w"
  14. android:layout_margin="0dp"
  15. android:padding="0dp"
  16. app:layout_constraintEnd_toEndOf="parent"
  17. app:layout_constraintStart_toStartOf="parent"
  18. app:layout_constraintTop_toTopOf="parent" />
  19.  
  20. <androidx.constraintlayout.widget.ConstraintLayout
  21. android:id="@+id/constraintLayout"
  22. android:layout_width="match_parent"
  23. android:layout_height="0dp"
  24. app:layout_constraintBottom_toBottomOf="parent"
  25. app:layout_constraintEnd_toEndOf="parent"
  26. app:layout_constraintStart_toStartOf="parent"
  27. app:layout_constraintTop_toBottomOf="@+id/imageView">
  28.  
  29.  
  30. <Button
  31. android:id="@+id/button"
  32. android:layout_width="wrap_content"
  33. android:layout_height="wrap_content"
  34. android:layout_marginBottom="115dp"
  35. android:text="Button"
  36. app:layout_constraintBottom_toBottomOf="parent"
  37. app:layout_constraintEnd_toEndOf="parent"
  38. app:layout_constraintStart_toStartOf="parent" />
  39. </androidx.constraintlayout.widget.ConstraintLayout>
  40. </androidx.constraintlayout.widget.ConstraintLayout>

逻辑代码

image

  1. StatusBarUtil.setTransparentForImageView(this,findViewById(R.id.constraintLayout));

StatusBarUtil官网

到此这篇关于Android 详解沉浸式状态栏的实现流程的文章就介绍到这了,更多相关Android 沉浸式状态栏内容请搜索w3xue以前的文章或继续浏览下面的相关文章希望大家以后多多支持w3xue!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号