Android ActionBar icons are missing -


i add icon actionbar can't actionbar show icons defined inside menu file. i've tried changing activity actionbaractivity but, if that, app crashes. tried changing theme theme.appcompat, didn't work. here code:

public class mainactivity extends activity {   private drawerlayout drawerlayout; private listview drawerlist; private actionbardrawertoggle drawertoggle;  private charsequence activitytitle; private charsequence itemtitle; private string[] tagtitles;     @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);       itemtitle = activitytitle = gettitle();     tagtitles = getresources().getstringarray(r.array.nav_options);     drawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout);     drawerlist = (listview) findviewbyid(r.id.left_drawer);      view header = getlayoutinflater().inflate(r.layout.drawer_cabecera, null);     drawerlist.addheaderview(header);       drawerlayout.setdrawershadow(r.drawable.drawer_shadow, gravitycompat.start);      arraylist<item_object> items = new arraylist<item_object>();     items.add(new item_object(tagtitles[1],r.drawable.ic_action_person));     items.add(new item_object(tagtitles[2],r.drawable.ic_action_search));     items.add(new item_object(tagtitles[3],r.drawable.ic_action_sd_storage));     items.add(new item_object(tagtitles[4],r.drawable.ic_action_cloud));     items.add(new item_object(tagtitles[5],r.drawable.ic_action_about));       drawerlist.setadapter(new navigationadapter(this, items));     drawerlist.setonitemclicklistener(new draweritemclicklistener());      getactionbar().setdisplayhomeasupenabled(true);     getactionbar().sethomebuttonenabled(true);      drawertoggle = new actionbardrawertoggle(             this,             drawerlayout,             //r.drawable.ic_drawer,             r.string.drawer_open,             r.string.drawer_close     ) {         public void ondrawerclosed(view view) {             getactionbar().settitle(itemtitle);          }          public void ondraweropened(view drawerview) {             getactionbar().settitle(activitytitle);           }     };      drawerlayout.setdrawerlistener(drawertoggle);      if (savedinstancestate == null) {         selectitem(0);     }  }  @override public boolean oncreateoptionsmenu(menu menu) {     menuinflater inflater = getmenuinflater();     inflater.inflate(r.menu.menu_main, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {      if (drawertoggle.onoptionsitemselected(item)) {         return true;     }     return super.onoptionsitemselected(item); }    private class draweritemclicklistener implements listview.onitemclicklistener     {     @override     public void onitemclick(adapterview<?> parent, view view, int position, long id) {         selectitem(position);     } }  private void selectitem(int position) {     fragment fragment = null;     class clase = null;     activity actividad = null;       switch (position) {          case 1:             fragment = new perfilfragment();             break;         case 2:             fragment = new seleccionarfragment();             break;         case 3:             fragment = new gestorfragment();             break;         case 4:             fragment = new drivefragment();             break;         case 5:             fragment = new infofragment();             break;         default:             break;      }      if (fragment != null) {          fragmentmanager fragmentmanager = getfragmentmanager();         fragmentmanager.begintransaction().replace(r.id.content_frame,     fragment).commit();          drawerlist.setitemchecked(position, true);         drawerlist.setselection(position);         settitle(tagtitles[position]);         drawerlayout.closedrawer(drawerlist);     } else {         // error al crear el fragmento         log.e("mainactivity", "error al crear el fragmento");      } }  @override public void settitle(charsequence title) {     itemtitle = title;     getactionbar().settitle(itemtitle); }  @override protected void onpostcreate(bundle savedinstancestate) {     super.onpostcreate(savedinstancestate);     // sincronizar el estado del drawer     drawertoggle.syncstate(); }  @override public void onconfigurationchanged(configuration newconfig) {     super.onconfigurationchanged(newconfig);     drawertoggle.onconfigurationchanged(newconfig); }   } 

in manifest have this:

<uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.vibrate"/> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.access_wifi_state" />  <uses-feature     android:name="android.hardware.wifi"     android:required="true" > </uses-feature>  <application     android:allowbackup="true"     android:icon="@drawable/logo1"     android:label="@string/app_name"     android:theme="@android:style/theme.holo.light.darkactionbar">      <activity         android:name=".loginactivity"         android:label="@string/app_name" >         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>      <activity android:name=".mainactivity"></activity>     <activity android:name=".gestoractivity"></activity>      <activity         android:name="etsiit.etsiitcast_def.seleccionaractivity"         android:screenorientation="portrait"         android:theme="@style/theme.appcompat.noactionbar" >         <intent-filter>             <action android:name="android.intent.action.main" />         </intent-filter>     </activity>    </application> 

here layout mainactivity

<android.support.v4.widget.drawerlayout      xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" >   <!-- main content view, view below consumes entire      space available using match_parent in both dimensions. --> <framelayout     android:id="@+id/content_frame"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="#ffffff"/>   <!-- android:layout_gravity="start" tells drawerlayout treat      sliding drawer on left side left-to-right      languages , on right side right-to-left languages.      drawer given fixed width in dp , extends full height of      container. solid background used contrast      content view. --> <listview     android:id="@+id/left_drawer"     android:layout_width="240dp"     android:layout_height="fill_parent"     android:layout_gravity="start"     android:choicemode="singlechoice"     android:divider="#cfcfcf"     android:dividerheight="2dp"     android:background="#424242"     android:textcolor="#424242"     />  </android.support.v4.widget.drawerlayout> 

and here menu_main.xml code:

<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_settings"     android:orderincategory="100"     android:title="@string/action_settings"     app:showasaction="never" />  <item     android:id="@+id/action_search"     android:orderincategory="200"     android:title="search"     android:icon="@drawable/cast_icon_blanco"     app:showasaction="ifroom"     ></item>  </menu> 

thank help.

step #1: replace occurrences of app: android: in menu resource. app: used appcompat-v7 or other libraries, , using native action bar.

step #2: if want action_settings appear toolbar button in action bar, replace android:showasaction="never" android:showasaction="ifroom" (or perhaps always instead of ifroom).


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -