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

 更新时间:2021年11月08日 17:22:30   作者:LuckyLazyPig  
沉浸式就是要给用户提供完全沉浸的体验,使用户有一种置身于虚拟世界之中的感觉。沉浸式模式就是整个屏幕中显示都是应用的内容,没有状态栏也没有导航栏,用户不会被一些系统的界面元素所打扰,让我们来实现下网上传的沸沸扬扬的安卓沉浸式状态栏

Android—沉浸式状态栏

image

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

去掉标题栏

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

效果

引入依赖

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

沉浸状态栏颜色

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

未设置颜色沉浸的状态:

image

逻辑代码:

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

image

布局文件

image

沉浸状态栏图片

未沉浸之前的效果

image

沉浸之后的效果

image

布局代码

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

image

<?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>

逻辑代码

image

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

StatusBarUtil官网

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

相关文章

  • Android okhttp的启动流程及源码解析

    Android okhttp的启动流程及源码解析

    这篇文章主要介绍了Android okhttp的启动流程及源码解析,帮助大家更好的理解和学习使用Android开发,感兴趣的朋友可以了解下
    2021-03-03
  • Android入门之ListView应用解析(一)

    Android入门之ListView应用解析(一)

    这篇文章主要介绍了Android入门之ListView应用,简单说明了ListView的实现,需要的朋友可以参考下
    2014-08-08
  • Android条纹进度条的实现(调整view宽度仿进度条)

    Android条纹进度条的实现(调整view宽度仿进度条)

    这篇文章主要给大家介绍了关于Android实现条纹进度条的方法,主要是通过调整view宽度仿进度条,文中通过示例代码介绍的非常详细,对各位Android开发者们具有一定的参考学习价值,需要的朋友们下面来一起看看吧
    2018-09-09
  • 教你如何搭建android源代码repo仓库

    教你如何搭建android源代码repo仓库

    这篇文章主要介绍了如何搭建android源代码repo仓库,如果你的开发是基于AOSP源码来建仓,那么搭建repo服务器和部署自己的repo仓库就是非常必要的工作了,本文给大家详细介绍搭建过程,感兴趣的朋友一起看看吧
    2022-07-07
  • Android实现语音播放与录音功能

    Android实现语音播放与录音功能

    这篇文章主要为大家详细介绍了Android实现语音播放与录音功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-07-07
  • android+json+php+mysql实现用户反馈功能方法解析

    android+json+php+mysql实现用户反馈功能方法解析

    相信每个项目都会有用户反馈建议等功能,这个实现的方法很多,下面是我实现的方法,供大家交流
    2012-11-11
  • android webView截图的4种方法

    android webView截图的4种方法

    这篇文章主要为大家详细介绍了android webView截图的4种方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-05-05
  • Android中WebView加载网页设置进度条

    Android中WebView加载网页设置进度条

    这篇文章主要为大家详细介绍了Android中WebView加载网页设置进度条,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-05-05
  • Android开发基础简化Toast调用方法详解

    Android开发基础简化Toast调用方法详解

    这篇文章主要为大家介绍了Android开发基础简化Toast调用方法的相关资料,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-02-02
  • 详解android adb常见用法

    详解android adb常见用法

    这篇文章主要介绍了详解android adb常见用法,对android开发测试的同学参考下
    2021-04-04

最新评论