Gradient Toolbar

I defined Gradient Drawable:

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

    <gradient
        android:endColor="#2F3F59"
        android:startColor="#4078A7"
        android:type="linear"
        android:angle="90" />

</shape>

And I installed it on the toolbar:

<style name="AppTheme.Toolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:textColorPrimary">@color/textcolorsecundary</item>
    <item name="actionMenuTextColor">@color/textcolorsecundary</item>
    <item name="android:textColorSecondary">@color/textcolorsecundary</item>
    <item name="android:background">@drawable/custom_background_blue</item>
</style>

It works! BUT

enter image description here

This is what happens to the name. he gets the same gradient. it looks really ugly, so I have to change that. How can I set the background of this infotext to be transparent?

+4
source share
3 answers

The solution is to disable the toolbar title:

this.getSupportActionBar().setDisplayShowTitleEnabled(false);

and add custom TextView:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/actionBarSize"
    android:elevation="2dp"
    android:focusable="false"
    android:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
    app:theme="@style/AppTheme.Toolbar" >

    <TextView
        android:id="@+id/toolbar_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:background="@null"
        android:text="Toolbar Title"
        android:textColor="@color/white"
        android:textSize="20sp"
        android:textStyle="bold" />

</android.support.v7.widget.Toolbar>
0
source

You can also solve this problem by setting the toolbar background to your resource.

mToolbar().setDrawable(R.drawable.your_gradient)

+2
source

link - Android

XML ,

0
source

All Articles