0

as the title suggest, I am getting a problem with the action Bar since i have recently installed android Api 22 under eclipse and jdk-7u76-windows-i586. Before the action Bar keep to display the icon with sdk version 7 and higher. But now icon is displayed only with sdk version 11 and higher,did I miss something or am I just blind?, here are the menu XML file and a screen shot:

<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/share"
      android:icon="@drawable/ic_action_add_group"
      android:title="share info"
      android:showAsAction="ifRoom" />

Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99
Yom
  • 3
  • 3

1 Answers1

0

Good i finally find the answer. But what is strange is that the code use to work before the sdk update:Means that this newer version of sdk has a good improvement about XML files. Then more errors get detected by the oldest versions.
Now how to solve problem with sherlock action Bar menu item?

  • if you want it to work for android api 11 and higher(Android 4.x or 5.x ) simply add this piece of code:
    Create a file in rsc/menu/ eg:menu.xml
    Now put:

    <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android" 
       >
    
    <item 
    android:id="@+id/send"
    android:title="@string/Send"
    android:icon="@drawable/ic_action_new_event"
    android:showAsAction="ifRoom" 
    />
    
     </menu>      
    

    And add a sample styles:in rsc/values/ :

       <style name="AppTheme"    
      parent="android:Theme.Holo.Light.DarkActionBar"  />
    
       </resources>
    

This in your Activity:

    @Override
    public boolean onCreateOptionsMenu(Menu menu){

    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.men, menu);


       return true;
    }
  • if you want it to work for android api 7 to 10(Android 2.x to Android 3.x) use something like this one in you class Activity:

      THEME == R.style.Theme_Sherlock_Light;
    
      @Override
    
      public boolean onCreateOptionsMenu(Menu menu){
    
    
    
       boolean isLight = THEME == R.style.Theme_Sherlock_Light;
    
      menu.add(R.string.Send)
    
     .setIcon(isLight ? R.drawable.ic_action_group : 
    
        R.drawable.ic_action_person)
         .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    
       menu.add(R.id.get)
                  .setIcon(isLight ?   
    
      R.drawable.ic_action_chat:          
       R.drawable.ic_action_chat)
           .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |           
    
          MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    
        menu.add("Refresh")
        .setIcon(isLight ? R.drawable.ic_action_time :        
    
        R.drawable.ic_action_volume_on)
         .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |   
         MenuItem.SHOW_AS_ACTION_WITH_TEXT);
      return true;
              }
    

    To respond to a click use somthing like this:

    @Override
     public boolean onOptionsItemSelected(MenuItem item) {
    
    
         if (item.toString()==getString(R.string.Send)) {
          Toast.makeText(MainActivity.this, "Got click: " + item,       
     Toast.LENGTH_SHORT).show();
     }
    
      return super.onOptionsItemSelected(item);
     } 
    

    And add a sample styles:in src/values/:

     <?xml version="1.0" encoding="utf-8"?>
    
    <resources>
    <style name="Theme.Styled"   
    
    parent="Theme.Sherlock.Light.DarkActionBar">
    
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
    
    <item      
    name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
         </style>
    
     <style name="Widget.Styled.ActionBar" 
    
                parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
    
    <item name="background">@drawable/bg_striped</item>
    <item name="android:background">@drawable/bg_striped</item>
    
    <item name="backgroundSplit">@drawable/bg_striped_split</item>
    <item         
    name="android:backgroundSplit">@drawable/bg_striped_split</item>
     </style>
     </resources>
    
Yom
  • 3
  • 3