0

Im using a custom actionbar theme (really just changed color) and disabling home icon (in main activity). I have 2 menu items that I want inflated and 'always' on the action bar. When i run the app they are both pushed into overflow.

I referred to this post here and went the route of using a custom namespace because Support v7 and still the same results. I was wondering if me using a custom actionbar theme is having anything to do with it?

here is my main_activity_actions.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:Velo="http://schemas.android.com/apk/res-auto">

    <item android:id="@+id/add_ride"
        android:title="@string/add_ride"
        android:icon="@drawable/ic_action_new"
        Velo:showAsAction="ifRoom"
        />

    <item android:id="@+id/action_settings"
        android:title="Settings"
        android:icon="@drawable/ic_action_overflow"
        Velo:showAsAction="ifRoom" />
</menu>

and here is the usual boilerplate inflater

    @Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_activity_actions, menu);
    return super.onCreateOptionsMenu(menu);
}

not sure if u guys wanna see anything else, but let me know.

Thanks in advance

EDIT : It's weird. I can use android:showAsAction="ifRoom" and get an error on it (red line underneath) and just ignore it and run and it works how I want, but if I use the namespace appname:showAsAction="ifRoom" it wont work. I mean I would like to do it the proper way, but whats the harm in ignoring this error?

Community
  • 1
  • 1
erp
  • 2,950
  • 9
  • 45
  • 90

2 Answers2

0

If you are using FragmentActivity, then you are not using AppCompat v7, which provides a consistent ActionBar from API 7 and up. You can continue to use android:showAsAction="ifRoom" and use FragmentActivity, but your menu items will only show up in the Action Bar on API 11 or higher devices (which is when the ActionBar became a built in part of Android).

The other approach is to switch to using AppCompat (a blog post about the newest revision, v21, may be helpful to read over) and use its ActionBarActivity. This would give you a consistent action bar experience before API 11, API 11-20, and API 21 (as API 21 changes quite a bit on how the Action Bar works).

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
0

From the FragmentActivity docs:

Note: If you want to implement an activity that includes an action bar, you should instead use the ActionBarActivity class, which is a subclass of this one, so allows you to use Fragment APIs on API level 7 and higher.

Since you want your activity to have an ActionBar and you're saying you want v7 support, extend ActionBarActivity. Then you'll need to use AppCompat theme.

If you want to use a base theme other than AppCompat, you'll have to extend Activity and change your minSdk to 11 or higher.

Basically to support API 7 you need to stick to the AppCompat theme from the support package.

Simas
  • 43,548
  • 10
  • 88
  • 116
  • okay, so if I change my `extends FragmentActivity` to `extends ActionBarActivity` and then in my themes.xml I change the parent to Theme.Appcompat.... then I should be good (is the gist of what your saying?) – erp Jan 08 '15 at 20:41
  • @erp Correct but it's styles not themes (should be). If you choose to go with the ActionBarActivity, then use the custom namespace, else if Activity then use `android`. – Simas Jan 08 '15 at 21:07