I need to make my toolbar
transparent, or at least remove that shaded line below it. Has anyone ever been in a similar situation?
I need to make my toolbar
transparent, or at least remove that shaded line below it. Has anyone ever been in a similar situation?
That "shaded line" that concerns you is elevation
. You can remove it by setting its value to 0dp
. So your code would look like this:
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="0dp"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
Regarding transparency, one way you can do this is to work with your style
. All you need to do is set the theme that hides toolbar
, set the action bar style with transparent background, and set this style to widget
of the toolbar.
<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>
<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>
<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"/>
Another way would look like this:
You can set the background for Android, the transparent color pattern, which works great. Add this to the layout you want a transparent toolbar:
android:background="@android:color/transparent"
If you want to change the alpha programmatically, you can modify the alpha in the background of the toolbar itself. Just get an instance of drawable
and set alpha
:
mToolbar = findViewById(R.id.my_toolbar);
mToolbar.getBackground().setAlpha(0);