Lord Goderick
Lord Goderick

Reputation: 985

How to make colorPrimary not show as toolbar background

I am trying to make the toolbar background color transparent however, the colorPrimary theme seems to be showing instead. When I set the background of the toolbar to a standard color, it overrides colorPrimary and work as intended, but is there a way for me to get rid of it completely as to make the toolbar background transparent? The reason that I still want colorPrimary is because of the recent apps tab color, I just want it to not show in the toolbar. Thank you.

enter image description here

Toolbar

 <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/transparent" />

Style

<style name="AppTheme1" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@android:color/transparent</item>
        <item name="colorAccent">@color/colorPrimary</item>
        <item name="android:windowLightStatusBar">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:elevation">0dp</item>
        <item name="elevation">0dp</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        <item name="android:textColorSecondary">@color/colorPrimary</item>
    </style>

Upvotes: 2

Views: 822

Answers (3)

Pial Kanti
Pial Kanti

Reputation: 1610

make toolbar.xml inside layout folder. Use below code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@android:color/transparent"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

And use this toolbar in your activity's xml. This way you will have a transparent toolbar.

Upvotes: 0

Rahul Karande
Rahul Karande

Reputation: 259

use this

 <?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/background_toolbar_translucent" />

background_toolbar_translucent.xml

<?xml version="1.0" encoding="utf-8"?>

<gradient
    android:angle="270"
    android:endColor="@android:color/transparent"
    android:startColor="@color/black_alpha_40"/>

colors.xml

<color name="black_alpha_40">#66000000</color>

Upvotes: 2

Umar Ata
Umar Ata

Reputation: 4258

use the code instead of only toolbar

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="8dp"
    android:background="@android:color/transparent"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@android:color/transparent"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">

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

</android.support.design.widget.AppBarLayout>

Upvotes: 3

Related Questions