Android 详解沉浸式状态栏的实现流程

作者:LuckyLazyPig 时间:2023-12-18 23:03:31 

Android—沉浸式状态栏

Android 详解沉浸式状态栏的实现流程

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

去掉标题栏

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

Android 详解沉浸式状态栏的实现流程

效果

Android 详解沉浸式状态栏的实现流程

引入依赖


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

沉浸状态栏颜色

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

未设置颜色沉浸的状态:

Android 详解沉浸式状态栏的实现流程

逻辑代码:


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

Android 详解沉浸式状态栏的实现流程

布局文件

Android 详解沉浸式状态栏的实现流程

沉浸状态栏图片

未沉浸之前的效果

Android 详解沉浸式状态栏的实现流程

沉浸之后的效果

Android 详解沉浸式状态栏的实现流程

布局代码

  • 将要沉浸的图片放在ImageView组件里面

  • 其他的组件放在一个布局里面

  • 通过一个setTransparentForImageView方法替换

Android 详解沉浸式状态栏的实现流程


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity">

<ImageView
       android:id="@+id/imageView"
       android:layout_width="0dp"
       android:layout_height="250dp"
       android:src="@drawable/w"
       android:layout_margin="0dp"
       android:padding="0dp"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.ConstraintLayout
       android:id="@+id/constraintLayout"
       android:layout_width="match_parent"
       android:layout_height="0dp"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toBottomOf="@+id/imageView">

<Button
           android:id="@+id/button"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginBottom="115dp"
           android:text="Button"
           app:layout_constraintBottom_toBottomOf="parent"
           app:layout_constraintEnd_toEndOf="parent"
           app:layout_constraintStart_toStartOf="parent" />
   </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

逻辑代码

Android 详解沉浸式状态栏的实现流程


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

StatusBarUtil官网

来源:https://blog.csdn.net/weixin_45882303/article/details/121179989

标签:Android,沉浸式,状态栏
0
投稿

猜你喜欢

  • Java编程实现排他锁代码详解

    2021-06-11 06:00:23
  • SpringBoot使用Thymeleaf模板引擎访问静态html的过程

    2023-11-25 10:04:44
  • SpringBoot Java后端实现okhttp3超时设置的方法实例

    2022-11-06 04:56:03
  • Java自动添加重写的toString方法详解

    2021-11-05 14:29:13
  • Spring循环依赖代码演示及解决方案

    2022-05-17 01:56:08
  • Android ProgressBar进度条使用详解

    2023-01-22 00:53:38
  • C#中datagridview的EditingControlShowing事件用法实例

    2021-05-27 23:08:43
  • 实例探究Android应用编写时Fragment的生命周期问题

    2022-12-15 19:57:22
  • 海量数据去重排序bitmap(位图法)在java中实现的两种方法

    2022-10-10 17:27:36
  • maven如何打包动态环境变量(包括启动脚本)

    2023-07-16 03:48:56
  • C# TrieTree介绍及实现方法

    2022-02-10 22:04:53
  • 深入解析C#设计模式中对桥接模式的具体运用

    2023-11-08 21:53:06
  • 使用itextpdf解决PDF合并的问题

    2023-09-21 04:47:16
  • C# XML基础入门小结(XML文件内容增删改查清)

    2022-10-18 17:12:02
  • C# Winform 调用系统接口操作 INI 配置文件的代码

    2023-03-04 11:49:54
  • Android HandlerThread案例详解

    2022-04-20 09:46:25
  • monkeyrunner之安卓开发环境搭建教程(1)

    2023-02-24 06:24:22
  • 在java代码中获取JVM参数的方法

    2022-08-15 01:05:43
  • C++实现特殊矩阵的压缩存储算法

    2023-11-17 23:53:06
  • JetBrains发布java代码质量检测工具Qodana早期预览版

    2022-11-22 20:49:57
  • asp之家 软件编程 m.aspxhome.com