Android 詳解沉浸式狀態(tài)欄的實現(xiàn)流程
Android—沉浸式狀態(tài)欄
我們的征程是星辰大海,而非人間煙塵
去掉標題欄
首先去掉對應主題下面的Android
自帶的ActionBar,只需要在對應主題下面加NoActionBar
效果
引入依賴
implementation 'com.jaeger.statusbarutil:library:1.5.1'
沉浸狀態(tài)欄顏色
沉浸式狀態(tài)欄,既可以把顏色實現(xiàn)沉浸,又可以把圖片實現(xiàn)沉浸。
未設置顏色沉浸的狀態(tài):
邏輯代碼:
StatusBarUtil.setColor(MainActivity.this,getResources().getColor(R.color.teal_200),0)
布局文件
沉浸狀態(tài)欄圖片
未沉浸之前的效果
沉浸之后的效果
布局代碼
- 將要沉浸的圖片放在ImageView組件里面
- 其他的組件放在一個布局里面
- 通過一個
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)欄的實現(xiàn)流程的文章就介紹到這了,更多相關(guān)Android 沉浸式狀態(tài)欄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
淺談Android輕量級的數(shù)據(jù)緩存框架RxCache
本篇文章主要介紹了淺談Android輕量級的數(shù)據(jù)緩存框架RxCache,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08Android編程開發(fā)之ScrollView嵌套GridView的方法
這篇文章主要介紹了Android編程開發(fā)之ScrollView嵌套GridView的方法,結(jié)合實例分析了ScrollView嵌套GridView的相關(guān)注意事項與處理技巧,需要的朋友可以參考下2015-12-12Android開發(fā)中requestfocus()無效的原因及解決辦法
這篇文章主要介紹了Android開發(fā)中requestfocus()無效的原因及解決辦法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-08-08Android播放assets文件里視頻文件相關(guān)問題分析
這篇文章主要介紹了Android播放assets文件里視頻文件相關(guān)問題分析,結(jié)合Android播放assets文件出現(xiàn)錯誤的實際問題給出了原因分析與解決方法參考,需要的朋友可以參考下2016-08-08Android studio實現(xiàn)滑動開關(guān)
這篇文章主要為大家詳細介紹了Android studio實現(xiàn)滑動開關(guān),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-03-03Android開發(fā)中MotionEvent坐標獲取方法分析
這篇文章主要介紹了Android開發(fā)中MotionEvent坐標獲取方法,結(jié)合實例形式分析了MotionEvent獲取坐標的相關(guān)函數(shù)使用方法與相關(guān)注意事項,需要的朋友可以參考下2016-02-02TextView長按復制的實現(xiàn)方法(總結(jié))
下面小編就為大家?guī)硪黄猅extView長按復制的實現(xiàn)方法(總結(jié))。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04