Android 詳解沉浸式狀態(tài)欄的實(shí)現(xiàn)流程
Android—沉浸式狀態(tài)欄

我們的征程是星辰大海,而非人間煙塵
去掉標(biāo)題欄
首先去掉對(duì)應(yīng)主題下面的Android自帶的ActionBar,只需要在對(duì)應(yīng)主題下面加NoActionBar

效果

引入依賴
implementation 'com.jaeger.statusbarutil:library:1.5.1'
沉浸狀態(tài)欄顏色
沉浸式狀態(tài)欄,既可以把顏色實(shí)現(xiàn)沉浸,又可以把圖片實(shí)現(xiàn)沉浸。
未設(shè)置顏色沉浸的狀態(tài):

邏輯代碼:
StatusBarUtil.setColor(MainActivity.this,getResources().getColor(R.color.teal_200),0)

布局文件

沉浸狀態(tài)欄圖片
未沉浸之前的效果

沉浸之后的效果

布局代碼
- 將要沉浸的圖片放在ImageView組件里面
- 其他的組件放在一個(gè)布局里面
- 通過一個(gè)
setTransparentForImageView方法替換

<?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>
邏輯代碼

StatusBarUtil.setTransparentForImageView(this,findViewById(R.id.constraintLayout));
到此這篇關(guān)于Android 詳解沉浸式狀態(tài)欄的實(shí)現(xiàn)流程的文章就介紹到這了,更多相關(guān)Android 沉浸式狀態(tài)欄內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android okhttp的啟動(dòng)流程及源碼解析
這篇文章主要介紹了Android okhttp的啟動(dòng)流程及源碼解析,幫助大家更好的理解和學(xué)習(xí)使用Android開發(fā),感興趣的朋友可以了解下2021-03-03
Android入門之ListView應(yīng)用解析(一)
這篇文章主要介紹了Android入門之ListView應(yīng)用,簡單說明了ListView的實(shí)現(xiàn),需要的朋友可以參考下2014-08-08
Android條紋進(jìn)度條的實(shí)現(xiàn)(調(diào)整view寬度仿進(jìn)度條)
這篇文章主要給大家介紹了關(guān)于Android實(shí)現(xiàn)條紋進(jìn)度條的方法,主要是通過調(diào)整view寬度仿進(jìn)度條,文中通過示例代碼介紹的非常詳細(xì),對(duì)各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧2018-09-09
android+json+php+mysql實(shí)現(xiàn)用戶反饋功能方法解析
相信每個(gè)項(xiàng)目都會(huì)有用戶反饋建議等功能,這個(gè)實(shí)現(xiàn)的方法很多,下面是我實(shí)現(xiàn)的方法,供大家交流2012-11-11
Android中WebView加載網(wǎng)頁設(shè)置進(jìn)度條
這篇文章主要為大家詳細(xì)介紹了Android中WebView加載網(wǎng)頁設(shè)置進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05
Android開發(fā)基礎(chǔ)簡化Toast調(diào)用方法詳解
這篇文章主要為大家介紹了Android開發(fā)基礎(chǔ)簡化Toast調(diào)用方法的相關(guān)資料,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02

