Remove action bar shadow - android

I want to remove the shadow that appears below the appcompat action bar so that the background of the action bar is completely transparent.
This is my theme and action bar style:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:actionBarStyle">#style/TransparentActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/TransparentActionBar</item>
<item name="windowActionBarOverlay">true</item>
</style>
<!-- Transparent Action Bar Style -->
<style name="TransparentActionBar"
parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#android:color/transparent</item>
<!-- Support library compatibility -->
<item name="background">#android:color/transparent</item>
<item name="elevation">0dp</item>
</style>
My minimum API level is 16
I've tried several solutions for this including:
Setting elevation to 0dp only works for Lollipop devices.
I get a "resource not found" error if I try to use windowContentOverlay
Setting the background of the root view to a color like white or transparent doesn't work
I've been trying to get this to work on 4.4.4 to no avail. Is it not possible below API level 21?
EDIT:
it turns out that the windowContentOverlay only works with the android prefix:
<item name="android:windowContentOverlay">#null<item/>
Trying to also define it without the prefix results in the resource not found error (this error points to the one with the prefix for whatever reason). I honestly don't understand why this occurs. I can only assume appcompat doesn't support the windowContentOverlay attribute.

Set windowContentOverlay to a drawable that will be drawn under the action bar. If you don't want a shadow set it to null, like so:
<item name="android:windowContentOverlay">#null</item>
and
<item name="windowContentOverlay">#null</item>
This works API level 16 and up.

Related

Changing the Status bar color on Android kitkat

Hey i am trying to change the color of the status bar to be the same as the action bar color (maybe transparent). On Android Lolipop it is not a problem but on Kitkat it looks like on this picture
I tried many others solution but it still not fix it.
here is the v19 xml style
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
This is not possible in Android 4.4 API level 19.
You can do it from Android 5.0 API level 21 and forward.

ColorPrimaryDark StatusBar Android

I am really getting crazy! I set in styles.xml and styles-v21.xml the attrs colorPrimaryDark and android:colorPrimaryDark but my statusBar does not change the color. I am using AppCompat-v22. Any idea?
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/brand_color</item>
<item name="colorPrimaryDark">#color/brand_color_dark</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabs</item>
<item name="actionBarTabStyle">#style/MyActionBarTabs</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="colorControlNormal">#color/brand_color</item>
<item name="colorControlActivated">#color/brand_color</item>
<item name="colorControlHighlight">#color/brand_color</item>
<item name="android:seekBarStyle">#style/SeekBarAppTheme</item>
<item name="android:windowAnimationStyle">#style/activity_animations</item>
</style>
styles-v21.xml:
<style name="AppTheme" parent="#style/AppBaseTheme">
<item name="android:colorPrimary">#color/brand_color</item>
<item name="android:colorPrimaryDark">#color/brand_color_dark</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
</style>
try add android:fitsSystemWindows="true" on your layout xml's root view
I have tried on device > API 21 device and found this attributes is necessary if you want change statusbar color
Your status bar color can only change in API 21+. In older devices, Android doesn't allow the developer to touch that attribute. Read this article, in Theming part:
When you set these attributes, AppCompat automatically propagates their values to the framework attributes on API 21+. This automatically colors the status bar and Overview (Recents) task entry.
On older platforms, AppCompat emulates the color theming where
possible. At the moment this is limited to coloring the action bar and
some widgets.
Hence, I think you tested with device < API 21, you should try with newer OS device.
just change your targetSdkVersion to 23

windowContentOverlay "no resource found that matches the given name"

I'm trying to create an app theme with a completely transparent appcompat action bar. I'm trying to remove the shadow below the action bar using windowContentOverlay, however for whatever reason I cannot build using this attribute. The elevation attribute only works for lollipop+ devices and my minimum API level is 16.
What is the issue here?
Error:(12, 29) No resource found that matches the given name: attr 'windowContentOverlay'.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:actionBarStyle">#style/TransparentActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowContentOverlay">#null</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/TransparentActionBar</item>
<item name="windowActionBarOverlay">true</item>
<item name="windowContentOverlay">#null</item>
</style>
<!-- Transparent Action Bar Style -->
<style name="TransparentActionBar"
parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#android:color/transparent</item>
<!-- Support library compatibility -->
<item name="background">#android:color/transparent</item>
</style>
Copied Drew's answer from the comments section.
It turns out that the windowContentOverlay only works with the android prefix: <item name="android:windowContentOverlay">#null<item/>.
Trying to also define it without the prefix results in the resource not found error (this error points to the one with the prefix for whatever reason).
I honestly don't understand why this occurs. I can only assume appcompat doesn't support the windowContentOverlay attribute.

Android Action bar won't obey background color

I've just updated my project to target API 22, and my action bar style appears to have broken. Despite setting the background to white, and the color to blue, I end up with a black action bar with white text.
Here's my application theme.
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:homeAsUpIndicator">#drawable/up_button</item>
<item name="android:actionMenuTextAppearance">#style/H4.Other</item>
<item name="android:actionMenuTextColor">#color/h4_other</item>
<item name="android:windowContentOverlay">#drawable/header_shadow</item>
<item name="android:buttonStyle">#style/ButtonStyle.NoCaps</item>
</style>
Here's my action bar style.
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:title">""</item>
<item name="android:background">#color/white</item>
<item name="android:height">#dimen/action_bar_height</item>
<item name="android:titleTextStyle">#style/H5.Blue</item>
</style>
Ok I figured this out. When you've updated the version of the app compat library you're using, the namespacing of some attributes needs to change. In my case it was changing from android:background to just background, among other things.

ActionBarSherlock Change Height?

I'm trying to change the height of my action bar to give it a more Material feel, but whatever I try never seems to work. Currently I have this:
<!-- Main Theme -->
<style name="WPTheme" parent="Theme.Sherlock">
<item name="actionBarStyle">#style/WPTheme.ActionBarStyle</item>
<item name="android:actionBarStyle">#style/WPTheme.ActionBarStyle</item>
<item name="android:actionBarWidgetTheme">#style/CustomActionOverflowDropDownText</item>
<item name="actionBarWidgetTheme">#style/CustomActionOverflowDropDownText</item>
<item name="android:textColor">#android:color/white</item>
<item name="android:actionOverflowButtonStyle">#style/MyOverflowButton</item>
<item name="textColorPrimaryInverse">#android:color/white</item>
<item name="android:windowBackground">#drawable/black</item>
</style>
<!-- Action Bar Theme -->
<style name="WPTheme.ActionBarStyle" parent="Widget.Sherlock.ActionBar">
<item name="background">#drawable/ic_bar_top</item>
<item name="android:background">#drawable/ic_bar_top</item>
<item name="actionBarSize">56dip</item>
<item name="android:actionBarSize">56dip</item>
<item name="actionOverflowButtonStyle">#style/Widget.Sherlock.ActionButton.Overflow</item>
<item name="dropDownListViewStyle">#style/Widget.Sherlock.Light.ListView.DropDown</item>
</style>
Is there any other solutions out there? Or am I just making some bone-head error here that I'm not picking up on? Thanks!
Changing of height of actionbarsherlock is not the solution.
Use Translucent system bars
You can now make the system bars partially translucent with new themes,
Check this project https://github.com/jgilfelt/SystemBarTint
If you're creating a custom theme, set one of these themes as the parent theme or include the windowTranslucentNavigation and windowTranslucentStatus style properties in your theme.
Hope this helps get you started.
Move <item name="actionBarSize">56dip</item> and <item name="android:actionBarSize">56dip</item> to your main theme.
Also, if you'd like, you can check out my blog post on achieving a material style action bar on older android versions here. Though I haven't written it to be used with ActionBarSherlock, with some slight modifications, you should be able to get the same thing working.

Categories

Resources