Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action bar does not show

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;     } 

enter image description here

But it does not show the action bar even if minSdkVersion is 11. What is the reason?

like image 714
Asha Soman Avatar asked Jul 29 '13 09:07

Asha Soman


People also ask

How do I get the action bar?

You may otherwise add the action bar by calling requestFeature(FEATURE_ACTION_BAR) or by declaring it in a custom theme with the windowActionBar property. Beginning with Android L (API level 21), the action bar may be represented by any Toolbar widget within the application layout.

How do I get the toolbar from action bar?

if you are using custom toolbar or ActionBar and you want to get reference of your toolbar/action bar from Fragments then you need to first get instance of your Main Activity from Fragment's onCreateView Method like below. ImageView vRightBtn = activity. toolbar. findViewById(R.

Where is the action bar?

In Android applications, ActionBar is the element present at the top of the activity screen. It is a salient feature of a mobile application that has a consistent presence over all its activities. It provides a visual structure to the app and contains some of the frequently used elements for the users.

How do I add action to action bar?

All action buttons and other items available in the action overflow are defined in an XML menu resource. To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.


2 Answers

Remove your theme for your actionbar activity in androidManifest file. Now it will work...

<application     android:allowBackup="true"     android:icon="@drawable/tasktodo"     android:label="@string/app_name"     > 

Don't add any theme in your application manifest file. If you added one, please remove and try running it...

like image 96
Satheesh Avatar answered Sep 18 '22 17:09

Satheesh


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:

public class YourActivity extends Activity  

into

public class YourActivity extends AppCompatActivity 
like image 37
sivi Avatar answered Sep 19 '22 17:09

sivi