Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Menu item always in support action bar

Tags:

enter image description hereI am working on android application . I have implemented supported action bar in it .I want to show option menu item always . But it is not showing . it is showing in drop down menu . my code for menu item given below.

<item     android:id="@+id/action_settings"     android:icon="@drawable/add_post"     android:title="@string/action_settings"      /> 

And code of ActionBar Activity is given below:-

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

any help will be appreciated.

like image 820
Nitesh Kabra Avatar asked Mar 07 '14 06:03

Nitesh Kabra


1 Answers

If you use the AppCompat ActionBar, you have to change your layout in this way:

<menu xmlns:android="http://schemas.android.com/apk/res/android"       xmlns:app="http://schemas.android.com/apk/res-auto" >     <item         android:id="@+id/action_settings"         android:icon="@drawable/add_post"         android:title="@string/action_settings"         app:showAsAction="always" /> </menu>   

showAsAction attribute will work only with a custom prefixe, see the documentation. According to it:

Notice that the showAsAction attribute above uses a custom namespace defined in the tag. This is necessary when using any XML attributes defined by the support library, because these attributes do not exist in the Android framework on older devices.

Hope this helps.

like image 137
Blo Avatar answered Oct 24 '22 16:10

Blo