簡體   English   中英

Android狀態欄和導航問題

[英]Android Status bar and Navigation issues

最近,我在Main_Activity使用了以下Java代碼:

(getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS))

用於狀態欄透明目的。 一切順利,但我的Android導航欄也采用了透明策略。 現在,我只需要透明狀態欄,而不需要導航欄。

您有兩種選擇,第一種,我建議您使用狀態庫樣式的外部庫,例如StatusBarUtil庫,它使您僅需一行即可滿足您的要求:

StatusBarUtil.setTransparent(Activity activity) // yo be placed in every activity you want the status bar to be transparent in

而且該庫不會影響導航欄。

只需確保首先在您的應用程序級別Gradle中實現該庫:

implementation'com.jaeger.statusbarutil:library:1.5.1'

第二種選擇是進行布局定制,如本教程中所述 ,您可以將以下內容添加到style.xml

<style name="AppTheme.TransparentTheme">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

並將此樣式應用於清單中的“活動”:

<activity
    android:name=".HomeActivity"
    android:theme="@style/AppTheme.TransparentTheme">
</activity>

如本教程中所述:

我已經將android:windowDrawsSystemBarBackgrounds設置為true。

這是一個標志,其描述如下:

指示此Window是否負責繪制系統欄背景的標志。 如果為true且窗口未漂浮,則系統欄將以透明背景繪制,並且該窗口中的相應區域將填充{@link android.R.attr#statusBarColor}和{@link android.R中指定的顏色.attr#navigationBarColor}。 對應於{@link android.view.WindowManager.LayoutParams#FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS}。

不要忘記將android:fitsSystemWindows="true"屬性添加到活動布局的頂部。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM