Android ActionBar not showing for AppCompat v7 on API 8 - android

I'm trying to display the ActionBar on my API 8 emulator by using the v7 AppCompat library, But it's not showing. Even the Split Action Bar does not show. The user has to click the menu button to show the options. I need 4 of the options to always be visible on my screen.
EDIT::
I have android:uiOptions="splitActionBarWhenNarrow", in case it helps...
Here is my menu xml code:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:symagine="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/action_twitter"
android:icon="#drawable/ic_action_twitter_icon"
android:orderInCategory="1"
android:showAsAction="always"
symagine:showAsAction="always"
android:title="#string/twitter_desc"/>
<item
android:id="#+id/action_share"
android:icon="#drawable/ic_action_share"
android:orderInCategory="5"
android:showAsAction="always"
symagine:showAsAction="always"
android:title="#string/share_desc"/>
<item
android:id="#+id/action_rightDrawer"
android:icon="#drawable/ic_action_i"
android:orderInCategory="6"
android:showAsAction="always"
symagine:showAsAction="always"
android:title="#string/action_info"/>
<item
android:id="#+id/action_facebook"
android:icon="#drawable/facebook_icon"
android:orderInCategory="2"
android:showAsAction="always"
symagine:showAsAction="always"
android:title="#string/facebook_desc"/>
<item
android:id="#+id/action_contact"
android:orderInCategory="3"
android:showAsAction="collapseActionView"
symagine:showAsAction="collapseActionView"
android:title="#string/action_contact"/>
<item
android:id="#+id/about_us"
android:orderInCategory="4"
android:showAsAction="collapseActionView"
symagine:showAsAction="collapseActionView"
android:title="#string/action_about_us"/>
</menu>
Here is my HomeActivity Code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
My custom action bar theme:
<style name="MyActionBarTheme" parent="#style/Theme.AppCompat">
<item name="android:windowActionBarOverlay" tools:ignore="NewApi">true</item>
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/MyCustomActionBar</item>
<!-- Support Library Compatibility -->
<item name="windowActionBarOverlay">true</item>
<item name="actionBarStyle">#style/MyCustomActionBar</item>
</style>
<style name="MyCustomActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#android:color/transparent</item>
<item name="android:backgroundSplit" tools:ignore="NewApi">#android:color/transparent</item>
<item name="android:logo" tools:ignore="NewApi">#drawable/ic_logo</item>
<item name="android:displayOptions" tools:ignore="NewApi">showHome|useLogo</item>
<!-- Support Library Compatibility -->
<item name="background">#android:color/transparent</item>
<item name="backgroundSplit">#android:color/transparent</item>
<item name="logo">#drawable/ic_logo</item>
<item name="displayOptions">showHome|useLogo</item>
</style>
Please can anyone tell me what's the problem? I looked at some previous questions and saw that you need to add [yourapp] namespace in showAsAciton. I did that but it still didnt make a difference. Thank you for your help.

guys! I found the solution. Apparently I wasn't extending ActionBarActivity so the ActionBar wasn't showing on devices less than Android 3.0.
Just thought you guys should know. I was earlier extending FragmentActivity and thought that if I changed it to ActionBarActivity, my Fragments which were running would not work...
But, it turns out that ActionBarActivity extends FragmentActivity so you needn't worry of the fact that one or the other might not work. Hope this helps someone out there!
Merry Christmas!!

You need to use a support library like actionbarsherlock. I think this tutorial will help you.

Related

Android API 16 MenuItem and Navigation Drawer Icon BackgroundColor

My App uses the AppCompat Library and is targeting v23 and minSDK is v16. I currently have an activity with a Navigation Drawer Fragment and I switch between 3 different fragments on my Main Activity.
My AppCompatToolbar color is blue, and my Activity background is gray.
On API 16: My Navigation Drawer icon (set as home button) and any MenuItem that is inflated from my fragments have a gray background around them on top of my blue toolbar.
On API 17+: Everything looks good. icon and MenuItems use the toolbar color.
Unfortunately I can't show pictures because I don't have enough rep but you get the idea.
I'm not doing anything funky in onPrepareOptionsMenu or onCreateOptionsMenu.I could not find any information on this and it's only happening on devices running API 16. Heres the relevant themes from styles.xml I'll paste whatever code is necessary.
<style name="AppThemeWhite" parent="AppTheme.Base">
<item name="android:textColor">#ffffff</item>
<item name="android:textColorSecondary">#FFFFFF</item>
<item name="android:textColorTertiary">#FFFFFF</item>
<item name="actionMenuTextAppearance">#style/ActionMenuItemWhite</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:editTextStyle">#style/LightEditText</item>
<item name="alertDialogTheme">#style/CustomAlertDialog</item>
<item name="colorAccent">#android:color/white</item>
<item name="colorControlHighlight">#color/appButtonHighlightColor</item>
<item name="android:textSize">#dimen/material_text_button</item>
<item name="colorButtonNormal">#color/appButtonColor</item>
<item name="colorPrimary">#color/appToolbarColor</item>
<item name="colorPrimaryDark">#color/appStatusBarColor</item>
<item name="android:dividerHeight">1px</item>
<item name="preferenceTheme">#style/PreferenceThemeOverlay.v14.Material</item>
<!-- Customize your theme here. -->
</style>
<style name="ToolbarTheme" parent="Base.ThemeOverlay.AppCompat.ActionBar">
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:actionMenuTextAppearance">#style/ActionMenuItemWhite</item>
</style>
<style name="ActionMenuItemWhite" parent="Widget.AppCompat.Light.ActionButton">
<item name="actionMenuTextColor">#color/appTextColor</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:textSize">#dimen/material_text_menu</item>
</style>
I might be misunderstanding here, but why are their MenuItems being inflated from Fragments? Normally the "v7.appcompat.toolbar" inflates it's MenuItems in the Main Activity.
Also just FYI, but in the recent past when I have tried to change some of the "ToolBar" settings by changing the "ActionBar" settings in the styles/themes, I have had mixed and unreliable results myself.
Why did you choose 16 as your minimum? It can be very tricky to have your App be backwards compatible starting from API 23 because there is a lot of code that doesn't work the same in Android when comparing pre-API 21 to post-API 21.
Sometimes styling needs both android:name items and name to support older androids and custom widgets... Example:
<item name="android:editTextStyle">#style/LightEditText</item>
<item name="editTextStyle">#style/LightEditText</item>
Also you can try to add this to your AppTheme.Base style:
<item name="actionButtonStyle">#style/ActionMenuItemWhite</item>
Please try change appcompat-v7 library version
compile 'com.android.support:appcompat-v7:23.1.1'
Bcoz not support v7:23.2+

Light theme action bar have weird artefact since AppCompat v21

Since I upgraded appcompat to v21 (now on v22.2.1), when using light theme, the action bar have a very odd artefact as seen on the screenshot below. When using dark theme, no problems whatsoever!
I tried to change the style of the action bar using this and it works, however there's no more title! All other ActionBar styles are showing the artefact.
<item name="actionBarStyle">#style/Widget.AppCompat.Light.ActionBar.TabBar</item>
Here are my dark/light themes definitions:
<style name="AT_Theme" parent="#style/Theme.AppCompat">
<item name="android:windowBackground">#android:color/black</item>
<item name="android:colorBackground">#android:color/black</item>
<item name="android:textColorPrimary">#ffffffff</item>
<item name="switchStyle">#style/switch_dark</item>
<item name="android:textAppearanceButton">#style/CustomTheme.ButtonTextAppearance</item>
<item name="android:listChoiceIndicatorSingle">#drawable/abc_btn_radio_material_light</item>
<item name="android:listChoiceIndicatorMultiple">#drawable/abc_btn_check_material_light</item>
</style>
<style name="AT_Theme_Light" parent="#style/Theme.AppCompat.Light">
<item name="android:windowBackground">#android:color/white</item>
<item name="android:colorBackground">#android:color/white</item>
<item name="android:textColorPrimary">#ff000000</item>
<item name="switchStyle">#style/switch_light</item>
<item name="android:textAppearanceButton">#style/CustomTheme.ButtonTextAppearance</item>
<item name="android:listChoiceIndicatorSingle">#drawable/abc_btn_radio_material</item>
<item name="android:listChoiceIndicatorMultiple">#drawable/abc_btn_check_material</item>
</style>
I tried tweaking/overriding a lot of things to no avail. Also search for a color definition or drawable that would do that, no result there either.
Please help me get rid of that artefact:
Turns out the solution was so simple:
1) Change actionBarStyle in app's custom theme, both light/dark works with this:
<item name="actionBarStyle">#style/Widget.AppCompat.Light.ActionBar.Toolbar</item>
2) Enable title in code:
ActionBar ab = aba.getSupportActionBar();
if (ab != null)
ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE,ActionBar.DISPLAY_SHOW_TITLE);

Issues with ActionBar

I'm having two issues using the V7 support version of Action Bar Activity.
This is what my application looks like:
And this is how I want it to look:
The first issues is that the text apart from the title is showing up black instead of grey.
I'm using the Display Home As Up Enabled option, but you can't see the arrow because its black on a black background as shown above (the arrow is there if you look really hard!)
This is the style I'm using for the actionbar - I'm fairly sure I'm doing something wrong here, but I can't figure out what:
<style name="PropertyCrossTheme" parent="#style/Theme.AppCompat.Light">
<!-- Any customizations for your app running on pre-3.0 devices here -->
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:actionMenuTextAppearance">#style/ActionBar.MenuTextStyle</item>
</style>
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:titleTextStyle">#style/ActionBar.TitleText</item>
</style>
<style name="ActionBar.TitleText" parent="#android:style/TextAppearance">
<item name="android:textColor">#android:color/white</item>
</style>
<style name="ActionBar.MenuTextStyle" parent="android:style/TextAppearance">
<item name="android:textColor">#android:color/white</item>
</style>
The second issue is that my add to favourite/remove from favourite option is always being pushed into hidden menu.
This is my menu xml:
<item android:id="#+id/favourites_add_item" android:title="#string/favourites_add"
android:icon="#drawable/nostar" android:showAsAction="always|withText" />
<item android:id="#+id/favourites_remove_item" android:title="#string/favourites_remove"
android:icon="#drawable/star" android:showAsAction="always|withText" />
And in code I'm adding the menu like this (I know it's c# - I'm using Xamarin, but I don't think that's the reason for the issue, so please just pretend it's java :-D):
public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.favourites_toggle, menu);
return true;
}
public override bool OnPrepareOptionsMenu(IMenu menu)
{
IMenuItem addItem = menu.FindItem(Resource.Id.favourites_add_item);
addItem.SetVisible(!IsFavourited);
IMenuItem removeItem = menu.FindItem(Resource.Id.favourites_remove_item);
removeItem.SetVisible(IsFavourited);
return true;
}
Thanks
Ross
In the menu xml, try removing "|withText", so it looks like:
<item android:id="#+id/favourites_add_item" android:title="#string/favourites_add"
android:icon="#drawable/nostar" android:showAsAction="always" />
<item android:id="#+id/favourites_remove_item" android:title="#string/favourites_remove"
android:icon="#drawable/star" android:showAsAction="always" />
You are using Support v7, hence you need to use:
app:showAsAction="always|withText"
instead of
android:showAsAction="always|withText"
app should be:
xmlns:app="http://schemas.android.com/apk/res-auto"
Note, that when using withText you are forcing it to show the text associated with the Menu item, you probably don't want if you only want that star to show.

ActionbarSherlock overflow menu styling issue

I am following the examples on the ActionbarSherlock website
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/bg_striped</item>
<item name="android:background">#drawable/bg_striped</item>
<item name="backgroundSplit">#drawable/bg_striped_split</item>
<item name="android:backgroundSplit">#drawable/bg_striped_split</item>
</style>
however with this setup I am not able to change the style for the overflow menu.
the properties "android:popupMenuStyle" and "android:dropDownListViewStyle" is completely ignored.
If i change the themes parent to "Theme.Sherlock.Light" it works. Is this intentional? If not how would you style the overflow menu dropdown and at the same time keep the themes parent "Theme.Sherlock.Light.DarkActionBar" as per the example on the Sherlock website.
thanks
You should check out this actionbar style generator. It works great and should help resolve your issue: http://jgilfelt.github.com/android-actionbarstylegenerator/

Styling the Actionbarsherlock tabs

So I'm trying to style the tabs of my Actionbar, which I've implemented using the ActionBarSherlock library. This is my code:
<style name="Theme.AndroidDevelopers" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="actionBarTabStyle">#style/CustomActionBarStyle</item>
<item name="android:actionBarTabStyle">#style/CustomActionBarStyle</item>
<style name="CustomActionBarStyle" parent="Widget.Sherlock.Light.ActionBar.TabBar">
<item name="android:background">#drawable/actionbar_tab_bg</item>
</style>
At the second and third line, if I change actionBarTabStyle to actionBarStyle, my actionbar itself is changed to my wanted style (not very well, ofcourse), so the connections do work. However, trying to change the actionbar tabs (below it), has still no success.
I hope somebody can help me.
With Regards,
The following should work
<style name="Theme.app" parent="#style/Theme.Sherlock.Light">
<item name="android:actionBarTabBarStyle">#style/Theme.app.tabbar.style</item>
<item name="actionBarTabBarStyle">#style/Widget.app.ActionBar.TabBar</item>
</style>
<style name="Theme.app.tabbar.style" parent="#style/Theme.Sherlock.Light">
<item name="android:background">#FF0000</item>
<item name="background">#FF0000</item>
</style>
<style name="Widget.app.ActionBar.TabBar" parent="Widget.Sherlock.ActionBar.TabBar">
<item name="android:background">#FF0000</item>
<item name="background">#FF0000</item>
</style>
This makes the tabBar red.
You need to set two times the actionBarTabBarStyle. This is because of Android > 3.0 and Android <3.0
In your CustomActionBarStyle you need to have
<item name="android:background">#drawable/actionbar_tab_bg</item>
<item name="background">#drawable/actionbar_tab_bg</item>
Hope this helps :)
So I had some difficulties with the styling because of a certain way I found to add the tabs by code in the first place. Thank you for the responses, they all work.

Categories

Resources