Android : Search Icon not showing on Action Bar -


as title says trying add icon (for search purposes) in action bar item's title in 3 dot menu. here code use.

menu_main.xml :

<menu xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools" tools:context=".mainactivity">      <item android:id="@+id/action_search"         android:icon="@drawable/search"         android:orderincategory="100"         android:title="action_search"         app:showasaction="always"/>     </menu> 

the way inflate menu :

@override     public boolean oncreateoptionsmenu(menu menu) {         menuinflater inflater = getmenuinflater();         inflater.inflate(r.menu.menu_main, menu);         return super.oncreateoptionsmenu(menu);     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          if (id == r.id.action_search) {             return true;         }          return super.onoptionsitemselected(item);     } 

do guys know why happens ?

ps: have holo.light default theme app.

you using things native action bar (e.g., inheriting fragmentactivity) , things appcompat-v7 action bar backport (e.g., app:showasaction).

change menu_main.xml this:

<menu xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     tools:context=".mainactivity">      <item         android:id="@+id/action_search"         android:icon="@drawable/search"         android:orderincategory="100"         android:showasaction="always"         android:title="action_search" /> </menu> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -