[英]status bar colour shows white not transparent while using navigation drawer under status bar in Android Kitkat 4.4 version
我正在使用材質設計導航抽屜,其中我想在android kitkat 4.4版本的透明狀態欄下創建我的抽屜布局,因為我已經使用過fitsystemwindow true,但是當使用fitsystem window true時,它也顯示了白色statusbar我也使用過android:windowTranslucentStatus true和android:windowTranslucentNavigation在值-v19下的style.xml中為false,但仍向我顯示android kitkat 4.4中的白色狀態欄,很容易在lolipop中獲得我對statusbar的了解,因此如何在Android kitkat 4.4中使statusbar透明我有很多谷歌搜索,但非解決方案適用於我。請幫助我解決此問題。謝謝。
values-v19 / style.xml
<resources xmlns:android="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">false</item>
</style>
</resources>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:paddingTop="5dp"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark" />
<android.support.design.widget.TabLayout
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
app:tabGravity="fill"
app:tabIndicatorColor="#f8f880"
app:tabSelectedTextColor="#ff8800"
app:tabTextColor="#ffffff" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|right"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:src="@drawable/ic_done" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ffffff"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer" />
</android.support.v4.widget.DrawerLayout>
對於API 21+
<style name="AppTheme" parent="android:Theme.Holo.NoActionBar.TranslucentDecor">
...
</style>
對於API級別19+
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
此外,您的布局還應具有android:fitsSystemWindows="false"
注意:在Android KitKat中,除非使用以下解決方案,否則無法更改狀態欄的顏色,因為僅在Lollipop中,Google引入了statuBarColor屬性
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.