How to Make Toolbar Transparent

How to make Toolbar transparent?

All you need to is to define theme which hide action bar, define action bar style with transparent background and set this style to the toolbar widget. Please note that toolbar should be drawen as last view (over all view tree)

<style name="Theme.Custom" parent="@android:style/Theme.AppCompat">
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
</style>

<style name="CustomActionBar" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>

Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- Toolbar should be above content-->
<include layout="@layout/toolbar" />

</RelativeLayout>

Toolbar layout:

<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="wrap_content"
app:theme="@style/CustomActionBar"/>

NavigationComponents Transparent toolbar

The best way to handle Action Bars/Toolbars is to use Theme.NoActionBar and then create one on you own and set the background color to transparent.

This cloud look like this:

<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.settings.SettingsActivity">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/settingsToolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent" />

</com.google.android.material.appbar.AppBarLayout>

<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="10dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/appBarLayout"
app:navGraph="@navigation/settings_navigation" />

Unable to make toolbar transparent in Android

I was having the worst trouble trying to find a solution to this exact issue. I must have searched dozens of posts and come up empty handed. Finally, I happened on a post (I forget which page) that mentioned that the Android v7 Toolbar needs to be on TOP of the layout in order for transparency to work. Thankfully, it worked. So, hopefully this will help someone else:

Here's what you need:

  1. Define a layout for your activity like below
  2. Make sure the Toolbar is at the bottom of the XML so it'll be on top in the z-order.
  3. Use RelativeLayout so you can make sure the Toolbar is visually at the top left on the screen.
  4. @color/primary should be transparent (#00000000) OR you can set it in code if you need to use other colors as well.
  5. (OPTIONALLY) Either add "android:layout_marginTop="?android:attr/actionBarSize" to the container below OR add it in your code. Otherwise, some of the content in the FrameLayout will be underneath the action bar.

    <android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

    <ListView android:id="@+id/left_drawer"
    android:layout_width="260dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:layout_marginRight="8dp"
    android:layout_marginTop="?android:attr/actionBarSize"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="@color/drawer_background"
    />

    </android.support.v4.widget.DrawerLayout>

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

How to make toolbar in material-ui transparent?

if you want to make only a certain number of toolbar style changes, then doing it in the theme file is not recommended. Instead, use the makeStyles

export default function App() {
const classes = useStyles();
return (
<AppBar position="static" style={{ boxShadow: "none" }}>
<Toolbar classes={{root:classes.greenToolbar}} className="toptoolBar" >
Green
</Toolbar>
<div style={{ backgroundColor: "transparent" }}>
<Toolbar
classes={{ root: classes.transparentToolbar }}>
transparent
</Toolbar>
</div>
</AppBar>
);
}

const useStyles = makeStyles((theme) => ({
transparentToolbar: {
backgroundColor: "transparent",
color: "red"
},
greenToolbar:{
backgroundColor:'green'
}
}));

Here is the working demo :

Edit nervous-chatelet-3cp0h

How to make the toolbar transparent when the keyboard is active

From Activity, if you are using AppCompatActivity, you can set Toolbar background like this way-

     Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
mToolbar.setBackgroundColor(ContextCompat.getColor(this,android.R.color.transparent));

This works perfectly in my project.

From xml,
you can set your toolbar background like this way

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

This two methods working well in my project. I think it will work in your case as well.

How to make toolbar edge transparent?

Include the ToolBar inside the AppBarLayout, above TabLayout as below:

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:background="@drawable/menu_gradient"
android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/transparent"
android:id="@+id/main_toolbar"
android:elevation="4dp"
app:titleTextColor="#ffffff"
tools:ignore="MissingConstraints"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/logos_round" />

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


<android.support.design.widget.TabLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/tabs"
android:elevation="5dp"
android:background="@drawable/transparent"
app:tabTextColor="@color/colorPrimary"
app:tabTextAppearance="@style/customTabText"
app:tabMode="fixed">
</android.support.design.widget.TabLayout>

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


Related Topics



Leave a reply



Submit