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輕量級(jí)的數(shù)據(jù)緩存框架RxCache
本篇文章主要介紹了淺談Android輕量級(jí)的數(shù)據(jù)緩存框架RxCache,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
Android編程開發(fā)之ScrollView嵌套GridView的方法
這篇文章主要介紹了Android編程開發(fā)之ScrollView嵌套GridView的方法,結(jié)合實(shí)例分析了ScrollView嵌套GridView的相關(guān)注意事項(xiàng)與處理技巧,需要的朋友可以參考下2015-12-12
Android游戲之?dāng)?shù)獨(dú)游戲開發(fā)
這篇文章主要為大家詳細(xì)介紹了Android游戲之?dāng)?shù)獨(dú)游戲開發(fā)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
Android開發(fā)中requestfocus()無效的原因及解決辦法
這篇文章主要介紹了Android開發(fā)中requestfocus()無效的原因及解決辦法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-08-08
Android播放assets文件里視頻文件相關(guān)問題分析
這篇文章主要介紹了Android播放assets文件里視頻文件相關(guān)問題分析,結(jié)合Android播放assets文件出現(xiàn)錯(cuò)誤的實(shí)際問題給出了原因分析與解決方法參考,需要的朋友可以參考下2016-08-08
Android studio實(shí)現(xiàn)滑動(dòng)開關(guān)
這篇文章主要為大家詳細(xì)介紹了Android studio實(shí)現(xiàn)滑動(dòng)開關(guān),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03
Android開發(fā)中MotionEvent坐標(biāo)獲取方法分析
這篇文章主要介紹了Android開發(fā)中MotionEvent坐標(biāo)獲取方法,結(jié)合實(shí)例形式分析了MotionEvent獲取坐標(biāo)的相關(guān)函數(shù)使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-02-02
TextView長按復(fù)制的實(shí)現(xiàn)方法(總結(jié))
下面小編就為大家?guī)硪黄猅extView長按復(fù)制的實(shí)現(xiàn)方法(總結(jié))。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-04-04

