android - How to add a button to actionbar? -


i have tried adding looking @ various guides , stackoverflow topics, didn't help. various guides say, still unable settings icon @ action bar. mainactivity.class:

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      actionbar actionbar = getsupportactionbar();      actionbar.setdisplayhomeasupenabled(true);      if (savedinstancestate == null) {         getsupportfragmentmanager().begintransaction()                 .add(r.id.container, new placeholderfragment())                 .commit();     } }   @override public boolean oncreateoptionsmenu(menu menu) {     menuinflater inflater = getmenuinflater();     inflater.inflate(r.menu.entry_test, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item){     intent myintent = new intent(getapplicationcontext(),mainactivity.class);     startactivityforresult(myintent, 0);     return true; } 

entry_test.xml (this icon is):

    <menu xmlns:android="http://schemas.android.com/apk/res/android" >         <item             android:id="@+id/action_cart"             android:icon="@drawable/ic_action_settings"             android:orderincategory="100"             android:showasaction="always"             android:title="settings" />  </menu> 

the icon not displayed in action bar , when pressing "more" button (or whatever called), button appears @ bottom saying settings (title of it). thats it. doing wrong?

since using actionbar via support library, try following:

<menu xmlns:android="http://schemas.android.com/apk/res/android"        xmlns:yourapp="http://schemas.android.com/apk/res-auto">      <item         android:id="@+id/action_cart"         android:icon="@drawable/ic_action_settings"         android:orderincategory="100"         android:showasaction="always"         yourapp:showasaction="always"         android:title="settings" />  </menu>     

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -