Reputation: 13154
I use actionbarsherlock. The piece of code below is responsible for changing it's background to a custom one.
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="background">@drawable/actionbar_bg</item>
<item name="android:background">@drawable/actionbar_bg</item>
<...>
</style>
<style name="Theme.MyApp" parent="@style/Theme.Sherlock.Light">
<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
<..>
</style>
And it works for actionbarsherlock (on versions below honeycomb). But in ICS I have a shadow below actionbar which I don't want. What is the style item to make it disappear?
Upvotes: 220
Views: 148946
Reputation: 577
Add this toolbar.getBackground().setAlpha(0);
to inside OnCreate method. The add this:
android:elevation="0dp" android:background="@android:color/transparent
to your toolbar xml file.
Upvotes: 1
Reputation: 441
You must set app:elevation="0dp"
in the android.support.design.widget.AppBarLayout
and then it works.
<android.support.design.widget.AppBarLayout
app:elevation="0dp"... >
<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:popupTheme="@style/AppTheme.PopupOverlay" >
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
Upvotes: 30
Reputation: 99
Try This it helped me without changing theme . Put Your AppBarLayout inside any layout.Hope this will help you
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="false"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:layout_height="?attr/actionBarSize"
android:background="@color/white">
<ImageView
android:src="@drawable/go_grocery_logo"
android:layout_width="108dp"
android:layout_height="32dp" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
Upvotes: 1
Reputation: 1691
For Android 5.0, if you want to set it directly into a style use:
<item name="android:elevation">0dp</item>
and for Support library compatibility use:
<item name="elevation">0dp</item>
Example of style for a AppCompat light theme:
<style name="Theme.MyApp.ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- remove shadow below action bar -->
<!-- <item name="android:elevation">0dp</item> -->
<!-- Support library compatibility -->
<item name="elevation">0dp</item>
</style>
Then apply this custom ActionBar style to you app theme:
<style name="Theme.MyApp" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">@style/Theme.MyApp.ActionBar</item>
</style>
For pre 5.0 Android, add this too to your app theme:
<!-- Remove shadow below action bar Android < 5.0 -->
<item name="android:windowContentOverlay">@null</item>
Upvotes: 146
Reputation: 5053
Solution for Kotlin (Android 3.3, Kotlin 1.3.20)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportActionBar!!.elevation = 0f
}
Upvotes: 2
Reputation: 595
For Xamarin Developers, please use : SupportActionBar.Elevation = 0;
for AppCompatActivity
or ActionBar.Elevation = 0;
for non-compat Activities
Upvotes: 1
Reputation: 126
For those working on fragments and it disappeared after setting toolbar.getBackground().setAlpha(0);
or any disappearance, i think you have to bring your AppBarLayout to the last in the xml, so its Fragment then AppBarLayout then relativelayout/constraint/linear whichever u use.
Upvotes: 0
Reputation: 29
I have this same problem, and I have successfully solved this problem. All you have to do is just change the elevation to 0 floating point value in that activity in which you want to remove the elevation.
If you want to change it in an activity called MyActivity.java
so you have to get the ActionBar
first.
First import the ActionBar
class
import android.support.v7.app.ActionBar;
after importing you have to initialize a variable of action bar and set its elevation to 0.
private ActionBar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
.
.
toolbar=getSupportActionBar();
toolbar.setElevation(0);
.
.
}
Upvotes: 3
Reputation: 2696
app:elevation="0dp"
but not
android:elevation="0dp"
worked for me on android L
Upvotes: 19
Reputation: 1309
add app:elevation="0dp"
in AppBarLayout for hiding shadow in appbar
Upvotes: 56
Reputation: 8028
What is the style item to make it disappear?
In order to remove the shadow add this to your app theme:
<style name="MyAppTheme" parent="android:Theme.Holo.Light">
<item name="android:windowContentOverlay">@null</item>
</style>
UPDATE:
As @Quinny898 stated, on Android 5.0 this has changed, you have to call setElevation(0)
on your action bar. Note that if you're using the support library you must call it to that like so:
getSupportActionBar().setElevation(0);
Upvotes: 498
Reputation: 2028
On Android 5.0 this has changed, you have to call setElevation(0) on your action bar. Note that if you're using the support library you must call it to that like so:
getSupportActionBar().setElevation(0);
It's unaffected by the windowContentOverlay style item, so no changes to styles are required
Upvotes: 104
Reputation: 23962
If you are working with ActionBarSherlock
In your theme add this:
<style name="MyTheme" parent="Theme.Sherlock">
....
<item name="windowContentOverlay">@null</item>
<item name="android:windowContentOverlay">@null</item>
....
</style>
Upvotes: 39