How can I make a Toolbar with a transparent gradient background?

1

I need to achieve this effect in the Toolbar:

This is the code I use to call Toolbar :

//...
Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbarMap);
setSupportActionBar(myToolbar);

myToolbar.setTitleTextColor(getResources().getColor(R.color.textColor));

getSupportActionBar().setTitle(R.string.map_title);
myToolbar.setNavigationIcon(getResources().getDrawable(R.drawable.back));
myToolbar.setNavigationOnClickListener(new View.OnClickListener() {

//...
    
asked by Missael Rodriguez 21.10.2017 в 21:43
source

1 answer

2

Create a file in the drawable folder named fade_bg.xml and add this:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <gradient
        android:angle="90"
        android:startColor="#fff"
        android:endColor="#75ffffff"
        android:type="linear"
        />

</shape>

This what it does is create a gradient with the desired color and end with a white with opacity.

Then you assign a background to the Toolbar element:

  <android.support.v7.widget.Toolbar
            android:background="@drawable/fade_bg"


            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"                 
            app:popupTheme="@style/AppTheme.PopupOverlay" />

And this is the result:

    
answered by 22.10.2017 / 04:22
source