Ross Dargan
Ross Dargan

Reputation: 6021

Issues with ActionBar

I'm having two issues using the V7 support version of Action Bar Activity.

This is what my application looks like:

enter image description here

And this is how I want it to look:

enter image description here

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

Upvotes: 2

Views: 452

Answers (2)

Geir Sagberg
Geir Sagberg

Reputation: 9821

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" />

Upvotes: 2

Cheesebaron
Cheesebaron

Reputation: 24460

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.

Upvotes: 1

Related Questions