Difference between ActionBarSherlock and ActionBar Compatibility

后端 未结 7 1889
庸人自扰
庸人自扰 2020-11-28 00:39

What is the difference between ActionBarSherlock and Action Bar Compatibility

Fews days ago Google just released the ActionBar Compatibility that make me so confused

7条回答
  •  暖寄归人
    2020-11-28 01:16

    Just completing what @Kurtis Nusbaum with a pratical example.

    UPDATE: as @rudy-s said, with newest android support library (api 18), I saw they already have built-in support for actionbar (called ActionBarCompat class).

    I built two simple applications to show the visual difference between ActionBarSherlock and ActionBar Compatibility. See the comparatives images:

    App using compatibility library

    App using sherlock library

    Now the appearance when the menu button is pressed:

    App using compatibility on menu pressed

    App using sherlock on menu pressed


    As you can see, the images just enforce what was said. Action Bar Compatibility gives you the action bar only if the device that you're running on is API level 3.0 or above. While Sherlock is more general.

    Below you can see the application source.

    The menu xml file is the same:

    
    
    
    
    
    
    
    
    
    
    
    

    Compatibility's activity:

    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.activity_main);
         }
    
         @Override
         public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
         }
    }
    

    Sherlock's activity:

    public class MainActivity extends SherlockActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
        }
    
        @Override
        public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
            getSupportMenuInflater().inflate(R.menu.main, menu);
            return super.onCreateOptionsMenu(menu);
        }
    
    }
    

    An additional config was necessary on sherlock app: