简体   繁体   中英

Android change toolbar color and status bar color but keep statusbar shadow

I'd like to keep the shadow on the status bar but I need to programmatically change the toolbar and status bar color. I can do this, but if I programmatically set the status bar color, it loses the shadow (I believe it's the elevation)

I have android:fitsSystemWindows="true" on my root (coordlayout) I have this as my theme:

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

Im setting the toolbar color:

mToolbar.setBackgroundColor((Color.parseColor("#FF4040")));

How do I set both without losing the shadow?

default status bar color with shadow

setting the second color on toolbar

Try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM