Android StatusBar 透明化方法(不同的版本適配)
透明狀態(tài)欄(StatusBar)的全適配
狀態(tài)欄指定android手機(jī)上頂部顯示手機(jī)狀態(tài)信息的位置。
透明狀態(tài)欄是android 自4.4開始新加入的功能,他可以是狀態(tài)欄根據(jù)我們自己想要的顏色進(jìn)行定義,使titleBar能夠和狀態(tài)欄融為一體,增加沉浸感。
咱們需要對不同的版本適配StatusBar,下面咱們一個一個看
values/styles.xml
<resources> <style name="Theme.AppTheme.TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar" /> </resources>
values-v19/styles.xml
<resources>
<style name="Theme.AppTheme.TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
values-21/styles.xml
<resources>
<style name="Theme.AppTheme.TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
values-23/styles.xml
<resources>
<style name="Theme.AppTheme.TranslucentStatusBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowLightStatusBar">true</item>
</style>
</resources>
具體使用
public class ImagePreActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
findViewById(android.R.id.content).setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
}
setContentView(R.layout.activity_image_pre_layout);
}
}
<activity android:name=".ImagePreActivity" android:theme="@style/Theme.AppTheme.TranslucentStatusBar" />
顯示效果
4.3以下

4.4

5.0

6.0

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android開發(fā)獲取手機(jī)Mac地址適配所有Android版本
- 詳解Android版本適配:9.0 Pie
- 適配Android 8.0版本更新安裝與通知欄的一些坑
- Android6.0獲取動態(tài)權(quán)限代碼示例
- Android6.0 動態(tài)權(quán)限機(jī)制深入講解
- androidQ sd卡權(quán)限使用詳解
- AndroidQ分區(qū)存儲權(quán)限變更及適配的實(shí)現(xiàn)
- Android運(yùn)行時權(quán)限終極方案(PermissionX)
- Android 如何實(shí)現(xiàn)動態(tài)申請權(quán)限
- Android普通應(yīng)用升級為系統(tǒng)應(yīng)用并獲取系統(tǒng)權(quán)限的操作
- Android 實(shí)現(xiàn)永久性開啟adb 的root權(quán)限
- Android 拍照選擇圖片并上傳功能的實(shí)現(xiàn)思路(包含權(quán)限動態(tài)獲取)
- Android 版本、權(quán)限適配相關(guān)總結(jié)
相關(guān)文章
完美解決Android三星手機(jī)從圖庫選擇照片旋轉(zhuǎn)問題
這篇文章主要幫助大家完美解決了Android三星手機(jī)從圖庫選擇照片旋轉(zhuǎn)問題,很實(shí)用的解決小案例,感興趣的小伙伴們可以參考一下2016-04-04
textView 添加超鏈接(兩種實(shí)現(xiàn)方式)
在textView添加超鏈接,有兩種方式,第一種通過HTML格式化你的網(wǎng)址,一種是設(shè)置autolink,讓系統(tǒng)自動識別超鏈接,下面為大家介紹下這兩種方法的實(shí)現(xiàn)2013-06-06
Android空心圓及層疊效果實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了Android空心圓及層疊效果實(shí)現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10
簡單介紹Android開發(fā)中的Activity控件的基本概念
這篇文章主要介紹了Android開發(fā)中的Activity控件的基本概念,Activity控件的使用是安卓開發(fā)的基礎(chǔ)之一,需要的朋友可以參考下2015-12-12
Kotlin開發(fā)實(shí)戰(zhàn)之hello world
這篇文章主要為大家詳細(xì)介紹了Kotlin開發(fā)實(shí)戰(zhàn)之hello world的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05
Android自定義dialog簡單實(shí)現(xiàn)方法
這篇文章主要介紹了Android自定義dialog簡單實(shí)現(xiàn)方法,實(shí)例分析了Android自定義對話框的相關(guān)設(shè)置技巧,代碼備有詳細(xì)的注釋便于理解,需要的朋友可以參考下2016-01-01
Flutter使用socketIo實(shí)現(xiàn)實(shí)時通訊
本文主要介紹了Flutter使用socketIo實(shí)現(xiàn)實(shí)時通訊,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-07-07
Android Studio 實(shí)現(xiàn)文檔注釋的快捷鍵
這篇文章主要介紹了Android Studio 實(shí)現(xiàn)文檔注釋的快捷鍵,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03

