Android---QUMI实现沉浸式状态栏

沉浸式状态栏是指将 App 的状态栏与应用界面进行融合,使得应用界面能够占据整个屏幕的控件,从而提供更加沉浸式的用户体验。通过使用沉浸式状态栏,应用界面可以延伸到状态栏的区域,使得应用界面的内容更加丰富,同时也能够增加应用的视觉效果。

基本使用

1. 在 build.gradle 文件中添加如下依赖

implementation("com.qmuiteam:qmui:2.1.0")

2. 布局文件

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

    <TextView
        android:id="@+id/make_request"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Title"
        android:textSize="25sp"
        android:textStyle="bold"
        android:padding="8dp"
        android:gravity="center"
        android:background="#D5D6D6"
        android:fitsSystemWindows="true"
        />

</LinearLayout>

3. 代码里实现沉浸式效果

class MainActivity: AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        //TODO 设置沉浸式状态栏
        QMUIStatusBarHelper.translucent(this)
        //TODO 设置状态栏字体的颜色,这里设置为黑色
        QMUIStatusBarHelper.setStatusBarLightMode(this)
    }
}

当显示到状态栏部分的界面背景为白色时,我们需要设置状态栏字体的颜色为黑色。

a. 设置状态栏字体颜色为黑色

QMUIStatusBarHelper.setStatusBarLightMode(activity)

b. 设置状态栏字体颜色为白色

QMUIStatusBarHelper.setStatusBarDarkMode(activity)

android:fitsSystemWindows="true" 属性。当我们把界面顶部 View 的背景设置到状态栏时,该属性设置为 true 时,顶部 View 的内容部分就不会显示到状态栏。如下所示:

上图所示:左边的图是在布局文件中没有设置 android:fitsSystemWindows="true" 属性,可以看出 View 的内容部分也显示到了状态栏里。

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

别偷我的猪_09

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值