Status bar with three-color gradient in Android Studio

Asked

Viewed 313 times

1

How to make a status bar with a 3-color gradient (as in the image).inserir a descrição da imagem aqui

2 answers

2

for versions from API 21 you could set the status bar color as follows: Configure your app theme:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:statusBarColor">@drawable/statusbar_degrade</item>
</style>

And the Drawable file that will generate the color set for your gradient:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <gradient android:centerColor="#3046d7"
            android:startColor="#58d445"
            android:endColor="#1b8f0b" />
    </shape>
</item>
</selector>

Then you can set the colors and gradient format inside the statusbar_degrade file you created in the @drawable folder.

  • I managed to do this part, but I could not apply it to the activitys! @Eduardorafael

1


I’ve never tried but I believe you should create an xml gradient and apply it as background in your bar status, follow a gradient model with only two colors:

    <item android:state_pressed="true">
        <shape>
            <solid android:color="@android:color/holo_blue_light"></solid>
        </shape>
    </item>

    <item>
        <shape>
            <solid android:color="@android:color/white"></solid>
        </shape>
    </item>
</selector>

Then apply this xml as backgroud of your statusbar

Browser other questions tagged

You are not signed in. Login or sign up in order to post.