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
Post a Comment