0

I'm new to android programming and I found out that menu are not available for android 3.0 and up. And suggestions is to use Action Bar. So I have the following in my AndroidManifest.xml

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="Main" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden|screenSize"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 

In my main.xml for menu/action bar:

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/homeMenu" android:orderInCategory="100" android:title="@string/home" android:showAsAction="ifRoom"/> <item android:id="@+id/searchMenu" android:orderInCategory="200" android:title="@string/search" android:showAsAction="ifRoom"/> <item android:id="@+id/exitMenu" android:orderInCategory="300" android:title="@string/exit" android:showAsAction="ifRoom"/> </menu> 

But it only display activity title in action bar for Android ICS. What I want if possible is to have the menu for Android < 3.0 and Action Bar for Android 3.0 and up. Or if there are better approach for this.

I have onCreateOptionsMenu in my main activity:

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

The menu works perfectly for Android 2.3.6 but Action Bar didn't display as I expected for Android ICS.

Thanks

1
  • 1
    y do u want to do that...u can use the ActionBar in all the versions of Android using ActionBarSherlock Commented May 7, 2013 at 7:49

2 Answers 2

2

If you want a consistent look across Android versions you really should look into ActionBarSherlock

"The library will automatically use the native action bar when appropriate or will automatically wrap a custom implementation around your layouts. This allows you to easily develop an application with an action bar for every version of Android from 2.x and up."

Sign up to request clarification or add additional context in comments.

Comments

1

try this

android:showAsAction="always" 

instead of

android:showAsAction="ifRoom" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.