Android ActionBarSherlock Top Bar

后端 未结 2 1866
生来不讨喜
生来不讨喜 2020-12-28 11:07

\"enter

I want to have an Action Bar like foursquare. What I want is tabs such as

2条回答
  •  醉梦人生
    2020-12-28 11:35

    To achieve a Foursquare look you do not need to be thinking of creating a layout above the tabs. When using Actionbar Sherlock you only need to worry about:

    1. Making a background for the top bar
    2. Making a logo for the top bar
    3. Adding items in a menu.xml file that ActionbarSherlock will use to populate the top section with Buttons (as long as a style using Actionbar Sherlock style is attached to thw activity).

    So, for 1. and 2. it's all about using styles.xml file (should reside in the values folder in the res folder) like so:

    
    
    
    

    For 3. all you need to do is create menu items under menu.xml (should reside in the menu folder (if not there, create one in the res folder)):

    
         
    
     
    
    

    The last thing you have to do to see the menu items is use these functions in the activity:

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }
    
    public boolean onOptionsItemSelected (MenuItem item) {
    
        Intent intent;
    
        switch (item.getItemId())
        {   
        case R.id.menu_prefs:
    
            // Launch Preference Activity
            intent = new Intent(getBaseContext(), Preferences.class);           
            startActivity(intent);
            break;
        }
    
        return false;
    }
    

提交回复
热议问题