2016-10-22 41 views
0

的α值在Android我可以設置一個透明狀態欄與下面的樣式行:獲取狀態欄

<item name="android:windowTranslucentStatus">true</item> 

我想直接根據與狀態欄的相同的背景顏色狀態欄來顯示文本。我的問題是,如果我將背景顏色設置爲我的primaryColor,它會更亮一些,因爲我沒有將狀態欄的Alpha值添加到顏色中。

那麼如何從代碼中獲取狀態欄的alpha值以將其添加到我的背景顏色?

+0

您是否看到[this](http://stackoverflow.com/a/28041425/6950238)問題? –

+0

感謝這個答案,但它不是我正在尋找的。我想在狀態欄下面顯示一個視圖(創建一個擴展的效果)與理智的alpha值,並不想繪製在它後面。 – Cilenco

+0

你試過像[在這[]](http://stackoverflow.com/a/35150398/6950238)問題獲得截圖,並獲得對應於StatusBar的像素的alpha值,就像在[that](http://stackoverflow.com/問題/ 7645607/Android的檢查-α-的像素)? –

回答

0

你想要這樣嗎?

enter image description here

如果是的話。 Android 5.0之後。 您應該將colorPrimaryDark設置爲與colorPrimary相同。 colorPrimaryDark表示狀態欄顏色。 其中一個重要的一步,如果你的佈局像這樣的代碼:

<android.support.design.widget.AppBarLayout 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

</android.support.design.widget.AppBarLayout> 

刪除 「AppBarLayout」。更改爲:

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" />