導航:首頁 > 操作系統 > android狀態欄顏色透明

android狀態欄顏色透明

發布時間:2025-05-16 11:28:28

1. android 沉浸式狀態欄和透明狀態欄的區別

注意!兩種方法的區別:
第一種:為頂部欄跟隨當前activity的布局文件的背景的顏色,使用方便,不過也有點問題就是,如果有底部虛擬導航鍵的話,導航鍵的背景跟頂部的顏色一樣,比如:

第二種:是通過設置頂部欄的顏色來顯示的,可以解決第一種的不足,比如:

第一種使用方法:

第一、首先在values、values-v19、values-v21文件夾下的styles.xml都設置一個 Translucent System Bar 風格的Theme,如下圖:

values/style.xml:
<style name="TranslucentTheme" parent="AppTheme">
<!--在Android 4.4之前的版本上運行,直接跟隨系統主題-->
</style>123

values-v19/style.xml:
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>1234

values-v21/style.xml:
<style name="TranslucentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">true</item>
<!--Android 5.x開始需要把顏色設置透明,否則導航欄會呈現系統默認的淺灰色-->
<item name="android:statusBarColor">@android:color/transparent</item>
</style>123456

第二、在清單文件中配置需要沉浸式狀態欄的activity加入theme
<activity android:name=".ImageActivity" android:theme="@style/TranslucentTheme" />
<activity android:name=".ColorActivity" android:theme="@style/TranslucentTheme" />12

第三、在Activity的布局文件中的跟布局加入「android:fitsSystemWindows=」true」」,但是,這里需要區分一下,就是背景是圖片還是純色:

1.當背景為圖片時,布局可以這么寫:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/imgs_bj"
android:fitsSystemWindows="true">

</RelativeLayout>12345678

效果:

2.當背景為純色,我們需要對布局劃分一下,標題布局與內容布局,先把根布局背景設置成標題布局的背景色,然後標題背景色可以不用設置直接使用根布局的背景色,最後內容布局背景色設置為白色
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary" //根布局背景設置成「標題布局」想要的顏色
android:fitsSystemWindows="true"
android:orientation="vertical">

<!--標題布局-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="@color/color_31c27c">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="這是標題"
android:textColor="@android:color/white"
android:textSize="20sp" />

</RelativeLayout>

<!--內容布局-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white" //內容區域背景設置成白色
android:gravity="center"
android:orientation="vertical">

<Button
android:layout_marginTop="120dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="顯示信息"
android:onClick="showMsg"
/>
</LinearLayout>

</LinearLayout>

2. android沉浸式狀態欄有一條半透明的底色怎麼去掉

造成Android的SE已禁用有如下原因: 1.是自己刷機後沒有wipe,雙清。或手機在線ota升級後沒有自動雙清,導致系統緩存混亂,所以報錯。 2.是用了某些同步工具,同步聯系人,簡訊,通話記錄,相冊等導致的錯亂問題。 3.SIM卡上存儲的信息問題。 4.比如刪除了系統必備apk,或者是替換了不同版本的apk,導致的錯誤。 建議按照以下方法操作: 1.手機中是否安裝手機安全衛士軟體或者一些第三方軟體程序,如果有請卸載嘗試。 2.建議把機器恢復出廠設置,操作如下:設置-重置/隱私權/私人-恢復出廠 3.建議固件升級嘗試。(設置-關於設備-系統更新)

3. android導航欄與狀態欄顏色及透明度

首先創建一個空項目,如下圖

可以看到狀態欄是白字黑背景, 導航欄也是白圖標黑背景
嘿嘿, 我們先把狀態欄隱藏掉,在添加一個ImageView, 讓ImageView做背景(方便查看)

樣子如下:

將狀態欄和導航欄設置透明, 找到 Manifest.xml 文件, 在主題樣式中修改

android:statusBarColor 設置狀態欄背景色
android:navigationBarColor 同上
android:windowLightStatusBar 設置狀態欄文字色, true為深色, false為白色
android:windowLightNavigationBar 同上
android:windowTranslucentStatus 設置狀態欄半透明狀態, true為半透明, false為不透明
android:windowTranslucentNavigation 同上

最後兩個半透明狀態下面沒用, 可自己嘗試看效果

效果圖如下:

可以看到導航欄與狀態欄並沒有透明,原因是默認不能佔用狀態欄空間與導航欄空間,根布局背景為白色,所有這里顯示白色
可以通過設置 getWindow().getDecorView().setSystemUiVisibility() 來適配

View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 適配狀態欄空間
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 適配導航欄空間
效果如下:

閱讀全文

與android狀態欄顏色透明相關的資料

熱點內容
python讀取在線表格 瀏覽:1001
喝什麼茶能緩解壓抑 瀏覽:865
u命令無法打開 瀏覽:960
vue編譯後的js能爬嗎 瀏覽:453
解壓骰子推薦3代 瀏覽:749
安卓手機劃線密碼忘了怎麼解鎖 瀏覽:309
精美角度主圖指標源碼 瀏覽:278
程序員編程函數需要特別好嗎 瀏覽:181
fue加密毛發怎麼樣 瀏覽:929
網上考學歷app如何屏蔽 瀏覽:352
python矩陣庫 瀏覽:160
伺服器如何ping伺服器 瀏覽:281
雲伺服器雙機熱備怎麼做 瀏覽:100
安卓果盤高清帳號是什麼帳號 瀏覽:548
蘋果解激活鎖什麼叫伺服器解鎖 瀏覽:596
用海綿寶寶做解壓的東西 瀏覽:192
大pdf文件免費轉word 瀏覽:792
如何侵入ftp伺服器 瀏覽:192
智行app如何查詢學生票使用次數 瀏覽:736
程序員幾年後開始有前途 瀏覽:127