Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I make the color of a toolbar a gradient?

In android I have a primary light color and status bar, can I make these a gradient between #F3A183 and #EC6F66? If so how can I achieve this?

like image 696
C. Dowdall Avatar asked Mar 12 '16 09:03

C. Dowdall


3 Answers

<android.support.v7.widget.Toolbar
 android:id="@id/toolbar"
 app:theme="@style/my_toolbar"
 android:background="@drawable/ab_gradient"
 android:elevation="5dp"
 android:layout_gravity="top"
 android:layout_height="wrap_content"
 android:layout_width="match_parent"/>

ab_gradient.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="rectangle">

  <gradient
   android:type="linear"
   android:startColor="#F3A183"
   android:endColor="#EC6F66"
   android:angle="270"/>
</shape>
like image 91
iamdeowanshi Avatar answered Oct 28 '22 09:10

iamdeowanshi


Programmatically you can set Background of toolbar like this

toolbar.setBackgroundResource(R.drawable.gradient_one);

Your gradient may look like this

<shape
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle"
>
  <corners android:radius="9dp"/>

  <gradient
    android:startColor="#cc4151"
    android:centerColor="#d95a5e"
    android:endColor="#e27e70">
  </gradient>
</shape>
like image 25
Максим Сыроватка Avatar answered Oct 28 '22 09:10

Максим Сыроватка


You can also set the gradient color programmatically through the ActionBar

ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(AppCompatResources.getDrawable(context, R.drawable.toolbar_background));

toolbar_background drawable with the gradient colors as follows:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
    <gradient
        android:angle:="45"
        android:startColor="#F3A183"
        android:endColor="#EC6F66">
    </gradient>
    <size android:width="24dp"/>
    <size android:height="24dp"/>
</shape>
like image 24
Kingsley Onwus Avatar answered Oct 28 '22 07:10

Kingsley Onwus