Android-StatusBarUtil沉浸式状态栏(1)

本文介绍了如何使用StatusBarUtil库在Android应用中设置状态栏的颜色、透明度,以及实现沉浸式状态栏,包括对ImageView的处理和相关代码示例。
摘要由CSDN通过智能技术生成
  • 设置状态栏颜色

StatusBarUtil.setColor(Activity activity, int color)

  • 设置状态栏半透明

StatusBarUtil.setTranslucent(Activity activity, int statusBarAlpha)

//通过传入 statusBarAlpha 参数,可以改变状态栏的透明度值,默认值是112。

  • 设置状态栏全透明

StatusBarUtil.setTransparent(Activity activity)

  • 为使用 ImageView 作为头部的界面设置状态栏透明

StatusBarUtil.setTranslucentForImageView(Activity activity, int statusBarAlpha, View needOffsetView)

四、沉浸状态栏颜色

========================================================================

是不是已经有了明显改善,但是上面还有一块颜色格格不入

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

引入依赖

implementation ‘com.jaeger.statusbarutil:library:1.5.1’

未设置颜色沉浸的状态:

在这里插入图片描述

核心代码:

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

设置完成后的状态栏:

在这里插入图片描述

五、沉浸状态栏图片

========================================================================

未沉浸之前的效果:

在这里插入图片描述

设置完成后的状态栏:

在这里插入图片描述

核心代码:

StatusBarUtil.setTranslucentForImageView(this, 0, constraintLayout);

MainActivity代码

public class MainActivity extends AppCompatActivity {

ConstraintLayout constraintLayout;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

constraintLayout=findViewById(R.id.constraintlayout);

StatusBarUtil.setTranslucentForImageView(this, 0, constraintLayout);

}

}

XML代码

<?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/imageView3”

android:layout_width=“match_parent”

android:layout_height=“300dp”

app:layout_constraintEnd_toEndOf=“parent”

app:layout_constraintStart_toStartOf=“parent”

最后

我坚信,坚持学习,每天进步一点,滴水穿石,我们离成功都很近!
以下是总结出来的字节经典面试题目,包含:计算机网络,Kotlin,数据结构与算法,Framework源码,微信小程序,NDK音视频开发,计算机网络等。

字节高级Android经典面试题和答案


《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!
算机网络等。

字节高级Android经典面试题和答案

[外链图片转存中…(img-J5Lmhta7-1714463380988)]
[外链图片转存中…(img-b61XKwzN-1714463380989)]

《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》点击传送门,即可获取!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值