How to set background on toolbar in Android

I want to set the background of a transparent toolbar.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    android:elevation="4dp"
    android:id="@+id/tool_bar_org"
    android:paddingTop="0dp">

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

      

Here is my toolbar layout is not transparent

show only white

 toolbar = (Toolbar) findViewById(R.id.tool_bar_org);
 toolbar.getbackgroud().setAlpha(0);
 setSupportActionBar(toolbar);

      

Does not work. Could you please tell me how to make it transparent.

+3


source to share


1 answer


This is the theme I used in my project to make the appCompact ActionBar transparent, change it to suit your needs:

<style name="adhoctheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/adhocblack</item>
        <item name="actionBarStyle">@style/adhocblack</item>
        <item name="android:windowActionBarOverlay">true</item>
        <item name="windowActionBarOverlay">true</item>
    </style>

    <style name="adhocblack" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#0D000000</item>
        <item name="background">@color/appcompact_transparent_actionbar_bg</item>
        <item name="android:icon">@drawable/logo_header_2</item>
    </style>

      

Where appcompact_transparent_actionbar_bg = #0D000000



Important:

Take a look here to check how folders with different values ​​contain specific style files for rendering in different APIs

0


source







All Articles