0

I am developing an android app supporting API-9, the action bar with the name of the app appear but the problem is that items doesn't appear this is the menu file:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <!-- http://schemas.android.com/apk/lib/com.fakher.actualitefoot -->
    <!-- Settings -->
    <item
        android:id="@+id/action_refresh"
        android:icon="@drawable/ic_action_settings"
        android:title="@string/action_settings"
        app:showAsAction="never|withText" />

    <!-- Check updates -->
    <item
        android:id="@+id/action_check_updates"
        android:icon="@drawable/ic_action_refresh"
        android:title="@string/action_check_updates"
        app:showAsAction="never|withText" />

</menu>

the main class:

public class MainActivity extends FragmentActivity {

    private final Handler handler = new Handler();
    private PagerSlidingTabStrip tabs;
    private ViewPager pager;
    private PagerAdapter adapter;
    private AdView adView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ....
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    private Drawable.Callback drawableCallback = new Drawable.Callback() {
        @Override
        public void invalidateDrawable(Drawable who) {
            getActionBar().setBackgroundDrawable(who);
        }

        @Override
        public void scheduleDrawable(Drawable who, Runnable what, long when) {
            handler.postAtTime(what, when);
        }

        @Override
        public void unscheduleDrawable(Drawable who, Runnable what) {
            handler.removeCallbacks(what);
        }
    };

    @Override
    public void onPause() {
        adView.pause();
        super.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
        adView.resume();
    }

    @Override
    public void onDestroy() {
        adView.destroy();
        super.onDestroy();
    }

}

stykes.xml :

<resources>

    <style name="AppBaseTheme" parent="android:Theme.Light"></style>

    <style name="AppTheme" parent="AppBaseTheme">

        <item name="android:windowBackground">@color/background_window</item>
        <item name="android:actionBarStyle">@style/ActionBarStyle</item>
    </style>

    <style name="ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <!--<item name="android:icon">@drawable/ic_launcher</item>-->
        <item name="android:background">#ff127d08</item>
    </style>

</resources>

i want that the action bar show the menu containing items declared in the menu file Thx :)

2 Answers2

1

What stands out to me is that you have- app:showAsAction="never|withText", the "never" parameter will prevent the item from appearing. I think it should be changed to:

app:showAsAction="ifRoom" 

or:

app:showAsAction="always"

the "withText" may also mess it up. I'm new to android programming, so I may be wrong. but check that and let me know if it worked. And also, I can't see all of the code, But did you import android.support.v7.app.ActionBar (since the app is for API 9)? it won't function without that as well.

JBWhitmore
  • 11,576
  • 10
  • 38
  • 52
EFlisio
  • 51
  • 6
0

You appear to be trying to use the appcompat-v7 action bar backport. If that is the case, you have to inherit from AppCompatActivity (or its predecessor, ActionBarActivity), not FragmentActivity. Since AppCompatActivity and ActionBarActivity themselves extend FragmentActivity, you will not lose any fragment-related functionality.

Also:

  • Change all getActionBar() calls to getSupportActionBar()

  • Ensure that your theme is inheriting from Theme.AppCompat (or from something else that inherits from Theme.AppCompat

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • how can i change themes to make it inherite from Theme.AppCompat ? this is the –  May 26 '15 at 10:32
  • @SaHa: Change `parent="android:Theme.Light"` to `parent="android:Theme.AppCompat.Light"` – CommonsWare May 26 '15 at 10:33
  • it generated this error : Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.AppCompat.Light'. –  May 26 '15 at 11:04
  • i put the whole file in question. i can add styles/11 and styles/14 if you want, Thanks :) –  May 26 '15 at 11:05
  • @SaHa: Whoops, sorry, my mistake. That should be `parent="Theme.AppCompat.Light"`, without the `android:` part. – CommonsWare May 26 '15 at 11:07
  • error is chaned now : "Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. " please take a look at the whole styles.xml file in my question –  May 26 '15 at 11:09
  • @SaHa: Everywhere in your `styles.xml` that you are referring to something other than `AppCompat` (e.g., `@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse`), you either need to remove it or replace it with something that is `AppCompat`-based. – CommonsWare May 26 '15 at 11:14
  • this become another issue, i asked another question, this is the link http://stackoverflow.com/questions/30457212/action-bar-doesnt-accept-personal-styles thank you for your help –  May 26 '15 at 11:27