I tried to implement an action bar in my application.
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/itemAdd"
android:showAsAction="ifRoom|withText"
android:title="ADD">
</item>
<item
android:id="@+id/itemRefresh"
android:showAsAction="ifRoom|withText"
android:title="REFRESH">
</item>
<item
android:id="@+id/itemHelp"
android:title="HELP">
</item>
</menu>
And created menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
But it does not show the action bar even if minSdkVersion
is 11. What is the reason?
change Activity to AppCompatActivity in your class. That should be the easiest if you want to add it fast.. I'll add the code for someone who is new to Android OS:
into
Don't add any theme in your application manifest file. If you added one, please remove and try running it...
I import
import android.support.v7.app.AppCompatActivity;
then edit to
public class MainActivity extends AppCompatActivity
Add to dependencies
You have to set the style of your Activity to
Theme.Holo
or one of its variants for the ActionBar to show. If you want to keep backwards-compatibility, call setTheme in onCreate of your Activity:An application with a Manifest like this
Menu.xml like this
And Activity like this
Looks like this.
Are you sure your phone or emulator is running Android 3.0 or above? If not, you will end up with your screenshot.
To enable The Actionbar on older devices, you should use the AppCompat/support library (https://developer.android.com/tools/support-library/features.html)
this works. Put it in your