Setting ActionBar Elevation on pre-5.0 devices with AppCompat - android

I want to remove the shadow from the ActionBar and I read you do this:
getSupportActionBar().setElevation(0)
However this didn't seem to work on Pre 5.0 devices. Is that a bug? I am not using the Toolbar. Just regular ActionBar from the library.

If you are using the ActionBar (not the Toolbar) you should be able to remove the shadow below using this style:
<style name="MyAppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowContentOverlay">#null</item>
</style>

Related

Theme.MaterialComponents.Light theme from material library is broken?

I'm using material library on version 1.1.0.
First image are "Theme.MaterialComponents.Light" without any customization. i'm expecting light actionbar
Second image are "Theme.MaterialComponents.Light" with colorPrimary and colorPrimaryDark defined. actionbar now seams as expected but all other component are wrong
It seams that all components use colorPrimary instead of colorAccent or colorSecondary.
It appens on material library 1.0.0 and 1.1.0, but not on old AppCompat themes.
It's a bug or i missing somethings?
this is using directly #style/Theme.MaterialComponents.Light
this is using
<style name="Theme.MaterialComponents.Light.App">
<item name="colorPrimaryDark">#color/primary_dark_material_light</item>
<item name="colorPrimary">#color/primary_material_light</item>
</style>
To fix the "ipotetical bug" of material library i done an override of actionbar theme like this. it works but seams not much elegant
<style name="Theme.MaterialComponents.Light.App">
<item name="actionBarTheme">#style/Widget.MaterialComponents.Light.ActionBar.Solid.App</item>
<item name="colorPrimary">#any</item>
</style>
<style name="Widget.MaterialComponents.Light.ActionBar.Solid.App">
<item name="colorPrimary">#color/primary_material_light</item>
</style>

Show the ImageView behind the Appcompat ActionBar

I am using theme as:
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
I want to show the ImageView partly behind the the ActionBar. I have tried Show ImageView partly behind transparent ActionBar and searched on google, but can't find the appropriate solution.
Better use Toolbar or Support Toolbar
With Toolbar, you can add it in your XML File just like any other View.
In your Activitys onCreate call setActionBar(toolbar) / setSupportActionBar(toolbar)
Or try to add these two lines in your style:
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
But using the Toolbar is actually pretty simple and the new standard.
Read this to get started: http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html

App compat actionbar v21 app icon is not showing

I upgraded to avtionbar app compat v21 for material design purpose.
But I observed that its not showing the app icon in actionbar and navigation menu and back button is taking more space compare to old appcompat libs.
Have any one faced this issue? I searched a lot but did not found anything useful.
Below line is also not working.
getSupportActionBar().setLogo(R.drawable.ic_launcher);
I am using style for actionbar which is like
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:icon">#drawable/ic_action_bar</item>
<item name="android:background">#drawable/action_bar_bg</item>
<item name="android:windowContentOverlay">#null</item>
<!-- Support library compatibility -->
<item name="background">#drawable/action_bar_bg</item>
</style>
I am aware of other solution like Toolbar. But I am in middle of release and due to time constraint I am looking for some quick solution if available. Adding a Toolbar will require more time.
setIcon/setLogo method will only work if you have set DisplayOptions Try this -
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setIcon(R.drawable.ic_launcher);
You can also set options for displaying LOGO(just add constant ActionBar.DISPLAY_USE_LOGO). More information - displayOptions
I added this to my theme:
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
<item name="windowActionBar">true</item>
and then the ActionBar was back.
Note: if you use supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); then you can't just do that, but will have to add the Toolbar to your layout (which isnt that much work, anyway)
Use getSupportActionbar instead of actionbar
Actionbar actionbar = getSupportActionBar()
actionbar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionbar.setIcon(YOUR ICON);

ActionBar styling different tab background when below ActionBar

Is there a way to define ActionBar tab style so that it would have different backgrounds when tabs are in ActionBar and below it?
I can't seem to find a way to do that with theme configuration with these properties
<item name="android:actionBarTabStyle">#style/Custom.ActionBar.TabView</item>
<item name="android:actionBarTabBarStyle">#style/Custom.ActionBar.TabBar</item>
<item name="android:actionBarTabTextStyle">#style/Custom.ActionBar.TabText</item>
I can define tab background to be white in #style/Custom.ActionBar.TabBar. All is ok with ActionBar.NAVIGATION_MODE_TABS.
But when I switch to ActionBar.NAVIGATION_MODE_LIST it is placed inside ActionBar and it also becomes white. And thats is unwanted behavior.
You can control the behaviors and visibility of the action bar with the ActionBar APIs, which were added in Android 3.0 (API level 11)."
So, ActionBar will not work for your target environment which is at API level 10 (Android 2.3.3).
Just in case, if you target for minimum API level 11 , you can change ActionBar's background color by defining custom style, as:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
And, set "MyTheme" as theme for application / activity.
Hope this helps...

How can I have a drop shadow on my ActionBar (ActionBarSherlock)?

I am including my styled xml layout:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Styled" parent="Theme.Sherlock">
<item name="actionBarStyle">#style/Widget.MyApp.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.MyApp.ActionBar</item>
</style>
<style name="Widget.MyApp.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
<item name="titleTextStyle">#style/Widget.MyApp.TitleTextStyle</item>
<item name="background">#color/red</item>
<item name="android:background">#color/red</item>
<item name="windowContentOverlay">#null</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="Widget.MyApp.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<item name="android:textSize">21sp</item>
</style>
</resources>
Some of the search over internet suggests that use windowContentOverlay set to #null. But when i use it in the style xml it doesn't change anything. Can any one help what to do?
If you want to create a shadow below the ActionBar you have to set android:windowContentOverlay parameter on the application theme (in your code you are incorrectly setting it on the ActionBar style).
In your example it would be:
<style name="Theme.Styled" parent="Theme.Sherlock">
...
<item name="android:windowContentOverlay">#drawable/my_actionbar_shadow</item>
</style>
Using #null value removes the shadow.
This one line sets the shadow on ActionBar on Android 3.0 and newer. However if you are using ActionBarSherlock, it will not work as you expect. It would create the shadow on top of the window over the ActionBarSherlock on Android devices running system older than Android 4.0 (although ActionBar is present in the api since Android 3.0, ActionBarSherlock uses custom implementation for all Android versions older than Android 4.0).
To create the shadow below ActionBarSherlock you have to set windowContentOverlay parameter on the application theme (notice the missing android:).
<style name="Theme.Styled" parent="Theme.Sherlock">
...
<item name="windowContentOverlay">#drawable/my_actionbar_shadow</item>
</style>
Again, using #null removes the shadow.
Although this line works for ActionBarSherlock, it doesn't work on android devices running Android 4.0 and newer, no shadow is created under the ActionBar on such devices. So how to combine these two parameters to get the desired shadow under both ActionBar and ActionBarSherlock?
Use resource configuration qualifiers, in your case use platform version qualifiers.
In res/values/styles.xml use the second xml code. And in res/values-v14/styles.xml use the first xml code. Therefore the ActionBarSherlock version is used by default (for versions pre Android 4.0) and ActionBar version is used for Android 4.0 and newer.
Edit:
There is a bug in Android 4.3 (API level 18), android:windowContentOverlay does not work. It should be fixed in future release. In case you need it fixed in Android 4.3, you can find workarounds linked in the bug report.
As a previous answer did say use "windowContentOverlay" in the application theme and NOT the action bar style.
<style name="Theme.Styled" parent="Theme.Sherlock">
...
<item name="windowContentOverlay">#drawable/my_actionbar_shadow</item>
</style>
If you want a realistic shadow you can find one in the
"Your Android Folder"/platforms/android-16/data/res/drawable-hdpi/
ab_solid_shadow_holo.9.png and copy it to your drawable-hdpi folder then the end result is
<style name="Theme.Styled" parent="Theme.Sherlock">
...
<item name="windowContentOverlay">#drawable/ab_solid_shadow_holo</item>
</style>
In addition, above API21(Lollipop), you will need this in code, too.
getSupportActionBar().setElevation(0);

Categories

Resources