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?
<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>
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With