action bar

satya - Tuesday, February 01, 2011 8:52:39 PM

honeycomb actionbar

honeycomb actionbar

Search for: honeycomb actionbar

satya - Tuesday, February 01, 2011 9:28:58 PM

honeycomb actionbar

honeycomb actionbar

Search for: honeycomb actionbar

satya - Tuesday, February 01, 2011 9:29:32 PM

a bit of coverage on action bar

a bit of coverage on action bar

satya - Tuesday, February 01, 2011 9:32:53 PM

2010 io presentation on the subject

2010 io presentation on the subject

satya - Tuesday, February 01, 2011 11:04:42 PM

navigation_mode_list

navigation_mode_list

Search for: navigation_mode_list

satya - Wednesday, February 02, 2011 1:57:41 PM

ActionBar

ActionBar

Search Google for: ActionBar

Search Android Developers Group for: ActionBar

Search Android Beginers Group for: ActionBar

Search Google Code for: ActionBar

Search Android Issues Database for: ActionBar

satya - Thursday, February 03, 2011 10:33:23 AM

affordance

affordance

Search Google for: affordance

Search Android Developers Group for: affordance

Search Android Beginers Group for: affordance

Search Google Code for: affordance

Search Android Issues Database for: affordance

satya - Thursday, February 03, 2011 10:36:47 AM

wiki meaning for affordance

wiki meaning for affordance

Meaning: An easily discoverable action that a user can perform

satya - Thursday, February 03, 2011 10:39:11 AM

cognitive affordance

cognitive affordance

satya - Thursday, February 03, 2011 10:43:13 AM

Afforance related articles on the topic of software engineering

Afforance related articles on the topic of software engineering

satya - Thursday, February 03, 2011 2:43:12 PM

Seeting up the actionbar as a tabbed actionbar


public void workwithTabbedActionBar()
{
    ActionBar bar = this.getActionBar();
    bar.setTitle("Hellow there. how are you");
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    
    TabListener tl = new TabListener(this,this);
    
    Tab tab1 = bar.newTab();
    tab1.setText("Tab1");
    tab1.setTabListener(tl);
    bar.addTab(tab1);
    
    Tab tab2 = bar.newTab();
    tab2.setText("Tab2");
    tab2.setTabListener(tl);
    bar.addTab(tab2);
}

satya - Thursday, February 03, 2011 2:45:02 PM

Corresponding TabbedListener


public class TabListener extends BaseTester
implements ActionBar.TabListener
{
    private static String tag = "tc>";
    public TabListener(Context ctx, IReportBack target)
    {
        super(ctx, target);
    }
    public void onTabReselected(Tab tab, FragmentTransaction ft) 
    {
        this.mReportTo.reportBack(tag, "ontab re selected:" + tab.getText());
    }
    public void onTabSelected(Tab tab, FragmentTransaction ft) 
    {
        this.mReportTo.reportBack(tag, "ontab selected:" + tab.getText());
    }
    public void onTabUnselected(Tab tab, FragmentTransaction ft) 
    {
        this.mReportTo.reportBack(tag, "ontab un selected:" + tab.getText());
    }
}

Don't pay attention to the base classes and extraneous variables. Read the code for concepts.

satya - Thursday, February 03, 2011 2:47:46 PM

List navigation mode


public void workwithListActionBar()
{
    ActionBar bar = this.getActionBar();
    bar.setTitle("Hellow there. how are you");
    //bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    bar.setListNavigationCallbacks(
       new MyAdapter(this),new ListListener(this,this));
}

satya - Thursday, February 03, 2011 2:48:34 PM

MyAdapter: A spinner adapter


public class MyAdapter extends ArrayAdapter<String>
implements SpinnerAdapter
{
    public MyAdapter(Context ctx)
    {
        super(ctx,
          android.R.layout.simple_spinner_item, 
          new String[]{"one","two"});
        
        this.setDropDownViewResource(
          android.R.layout.simple_spinner_dropdown_item);
    }
    public View getDropDownView(
      int position, View convertView, ViewGroup parent)
    {
        return super.getDropDownView(
          position, convertView, parent);
    }
}

satya - Thursday, February 03, 2011 2:49:52 PM

Read on using spinners

Read on using spinners

satya - Thursday, February 03, 2011 2:51:16 PM

ListListener


public class ListListener 
extends BaseTester
implements ActionBar.OnNavigationListener
{
    public ListListener(
    Context ctx, IReportBack target)
    {
        super(ctx, target);
    }
    public boolean onNavigationItemSelected(
    int itemPosition, long itemId) 
    {
        this.mReportTo.reportBack(
          "list listener","ItemPostion:" + itemPosition);
        return true;
    }
}

satya - Thursday, February 03, 2011 2:52:26 PM

Making a menu item show up on actionbar


<item android:id="@+id/menu_list_nav"
    android:title="List Nav Activity" 
    android:icon="@drawable/creep001" 
    android:showAsAction="ifRoom"/>

satya - Thursday, February 03, 2011 2:55:08 PM

Or you can do this in code


MenuItem actionItem = menu.add("Action Button");        
actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);        
actionItem.setIcon(android.R.drawable.ic_menu_share);

satya - Saturday, February 05, 2011 10:34:00 AM

The three modes of an action bar


Standard: NAVIGATION_MODE_STANDARD
Tab: NAVIGATION_MODE_TABS
List: NAVIGATION_MODE_LIST

These modes seem to be exclusive for a given action bar. Even some of the methods of the action bar class are applicable only if the action bar is in that mode.

In a way they are perhaps more like sub classes from a base class.

satya - Saturday, February 05, 2011 10:36:14 AM

In all modes clicking on the home icon will result in a menu android.R.id.home


protected boolean onMenuItemSelected(MenuItem item)
{
  if (item.getItemId() == android.R.id.home)
  {
    this.reportBack(tag,"Home Pressed");
  }
  return true;
}

satya - Saturday, February 05, 2011 11:19:28 AM

getting navigation mode


private int getNavMode()
{
  ActionBar bar = this.getActionBar();
  return bar.getNavigationMode();
}

satya - Saturday, February 05, 2011 1:17:27 PM

NAVIGATION_MODE_DROPDOWN_LIST

NAVIGATION_MODE_DROPDOWN_LIST

Search Google for: NAVIGATION_MODE_DROPDOWN_LIST

Search Android Developers Group for: NAVIGATION_MODE_DROPDOWN_LIST

Search Android Beginers Group for: NAVIGATION_MODE_DROPDOWN_LIST

Search Google Code for: NAVIGATION_MODE_DROPDOWN_LIST

Search Android Issues Database for: NAVIGATION_MODE_DROPDOWN_LIST

satya - Saturday, February 05, 2011 1:22:33 PM

More on this mode

Looks like the value for both

NAVIGATION_MODE_LIST
NAVIGATION_MODE_DROPDOWN_LIST

appears to be the same.

The only affect of setting one mode or vs the other, (betweent these two modes), is wether to show the titles or not. I suppose those can be done through display options setting.

satya - Saturday, February 05, 2011 1:27:43 PM

standard action bar


public void workwithStandardActionBar()
{
    ActionBar bar = this.getActionBar();
    bar.setTitle("Standard Navigation Mode Title");
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    //test to see what happens if you were to attach tabs
    attachTabs(bar);
}
public void attachTabs(ActionBar bar)
{
    TabListener tl = new TabListener(this,this);
    
    Tab tab1 = bar.newTab();
    tab1.setText("Tab1");
    tab1.setTabListener(tl);
    bar.addTab(tab1);
    
    Tab tab2 = bar.newTab();
    tab2.setText("Tab2");
    tab2.setTabListener(tl);
    bar.addTab(tab2);
}

Attaching tabs in the mode ignores them.

I will upload the look and feel of various action bar modes in a short while

satya - Saturday, February 05, 2011 1:29:03 PM

work with dropdownlist actionbar


public void workwithDropdownListActionBar()
{
    ActionBar bar = this.getActionBar();
    bar.setTitle("Hellow there. how are you");
    //bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_DROPDOWN_LIST);
    
    bar.setDropdownNavigationMode(
      new MyAdapter(this),new ListListener(this,this));
}

satya - Saturday, February 05, 2011 1:42:53 PM

What does standard nav look like

Click on the image for a bigger image

satya - Saturday, February 05, 2011 1:49:13 PM

Key points of a standard action bar


Home icon invokes R.id.home menu item
Some menu items can be added as action icons
(look top right funny icons)
(icons from: androidicons.com: thank you)
An icontest icon shows only as text in the menu
clicking on title nothing happens
Setting tabs won't give an error but won't show tabs

satya - Saturday, February 05, 2011 1:49:51 PM

Tab Navigation look and feel

Click on the image for a bigger image

satya - Saturday, February 05, 2011 1:50:46 PM

behavior


Tabs show up
tab listener needs to be there
(if not a run time exception)
Home icon works as in standard

satya - Saturday, February 05, 2011 1:51:14 PM

List Navigation mode look and feel

Click on the image for a bigger image

satya - Saturday, February 05, 2011 1:51:56 PM

aspects


You need a list listener
behaves much like a tab
standard nav behavior is still there

satya - Saturday, February 05, 2011 1:52:21 PM

dropdown nav

Click on the image for a bigger image

satya - Saturday, February 05, 2011 1:53:17 PM

aspects


very much like list nav
undocumented
(may go away)
title is not displayed
(this can be done through list nav)
(with title display option turned off)
(i suppose.)

satya - Saturday, February 05, 2011 2:27:05 PM

You can download the complete project here

Download Eclipse ADT Importable Zip File

Please note the link above is a zip file download.

satya - Saturday, February 05, 2011 2:34:43 PM

What does this project do


Create 4 separate activities
(Each activity with a separate nav mode action bar)
provide a menu to navigate between 4 activities
show how the home icon behaves
show what parts of the action bar is shown in each mode
capture and log mouse actions as tabs are pressed
(these are logged right on the screen)
(no need to see the log.d)

satya - Sunday, February 06, 2011 7:52:46 PM

Actionbar and Backport

Actionbar and Backport

satya - Sunday, February 06, 2011 7:57:32 PM

Actionbar and Backport

Actionbar and Backport

There is some news that some or most of the fragment related code that is in 3.0 may be made available in older versions of Android as a set of libraries.

However from the link above Romain Guy indicates that the ActionBar API is more closely tied to other APIs of 3.0 such as the Menus and hence most likely will not be made available as part of this backport exercise.

satya - Wednesday, November 02, 2011 10:56:47 AM

well we are in ICS now. Actionbar is now part of phones too

well we are in ICS now. Actionbar is now part of phones too

satya - Wednesday, November 02, 2011 11:00:36 AM

A consort of ifRoom: withText


android:showAsAction="ifRoom|withText"

satya - Wednesday, November 02, 2011 11:01:17 AM

You can do this if your app is provisioned with an actionbar


ActionBar actionBar = getActionBar();
if (actionBar!=null)
   actionBar.hide();

satya - Wednesday, November 02, 2011 11:01:42 AM

This will remove the actiobar


<activity android:theme="@android:style/Theme.Holo.NoActionBar">

satya - Wednesday, November 02, 2011 11:02:35 AM

Read this to undestand themes

Read this to undestand themes

satya - Wednesday, November 02, 2011 1:39:41 PM

nature of flag_activity_clear_top

If you respond to the application icon by returning to the home activity, you should include the FLAG_ACTIVITY_CLEAR_TOP flag in the Intent. With this flag, if the activity you're starting already exists in the current task, then all activities on top of it are destroyed and it is brought to the front. You should favor this approach, because going "home" is an action that's equivalent to "going back" and you should usually not create a new instance of the home activity. Otherwise, you might end up with a long stack of activities in the current task

satya - Wednesday, November 02, 2011 1:42:25 PM

an example


boolean onOptionsItemSelected(MenuItem item) 
{    
    switch (item.getItemId()) 
    {        
        case android.R.id.home:            
            // app icon in Action Bar clicked; go home            
            Intent intent = new Intent(this, HomeActivity.class);            
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);            
            startActivity(intent);            
            return true;        
        default:            
        return super.onOptionsItemSelected(item);    
    }
}

satya - Wednesday, November 02, 2011 1:42:44 PM

you can use the home to go up as well

you can use the home to go up as well

satya - Wednesday, November 02, 2011 1:43:25 PM

use the method


actionBar.setDisplayHomeAsUpEnabled(true)

satya - Wednesday, November 02, 2011 1:44:33 PM

when you are trying to go back: Clear Top

think hard and use the clear top flag

satya - Wednesday, November 02, 2011 1:49:18 PM

You can insert something like a searchview in the action bar

You can insert something like a searchview in the action bar

satya - Wednesday, November 02, 2011 1:49:27 PM

searchview

searchview

satya - Friday, November 04, 2011 11:10:16 AM

Read this to understand search better

Read this to understand search better

satya - Friday, November 04, 2011 11:12:07 AM

Steps needed to put a search view in an action bar


add a menu item with search view
create a search results activity that can respond
create an xml file: xml/searchable.xml
define the search results activity in the manifest file
in onCreateOptions hook up the searchview 
  to the search results activity.

satya - Friday, November 04, 2011 2:54:01 PM

Here is a menu item for actionbar


<item android:id="@+id/menu_search"
    android:title="Search"
    android:showAsAction="ifRoom"  
    android:actionViewClass="android.widget.SearchView"            
    />

satya - Friday, November 04, 2011 2:55:42 PM

A search results activity


public class SearchResultsActivity 
{
    private static String tag=
      "Search Results Activity";
    
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        final Intent queryIntent = getIntent();
        final String queryAction = queryIntent.getAction();
        if (Intent.ACTION_SEARCH.equals(queryAction)) 
        {
           Log.d(tag,"onCreate: intent for search");
           this.doSearchQuery(queryIntent);
        }
        else {
           Log.d(tag,"onCreate: intent NOT for search");
        }
    }
    @Override
    public void onNewIntent(final Intent newIntent) 
    {
        super.onNewIntent(newIntent);
        Log.d(tag,"new intent calling me");
        
        // get and process search query here
        final Intent queryIntent = getIntent();
        final String queryAction = queryIntent.getAction();
        if (Intent.ACTION_SEARCH.equals(queryAction)) 
        {
           this.doSearchQuery(queryIntent);
           Log.d(tag,"new intent for search");
        }
        else {
           Log.d(tag,"new intent NOT for search");
        }
    }
    private void doSearchQuery(final Intent queryIntent) 
    {
        final String queryString = 
           queryIntent.getStringExtra(SearchManager.QUERY);
        Log.d(tag, queryString);
    }
}//eof-class

satya - Friday, November 04, 2011 2:56:25 PM

xml/searchable.xml


<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/slabel"
    android:hint="@string/shint" 
/>
<!-- /res/xml/searchable.xml -->

satya - Friday, November 04, 2011 2:57:57 PM

search results activity in the manifest file


<activity android:name=".SearchResultsActivity"
   android:label="Search Results">
     <intent-filter>
        <action android:name="android.intent.action.SEARCH"/>
      </intent-filter>
     <meta-data android:name="android.app.searchable"
                        android:resource="@xml/searchable"/>
</activity>

satya - Friday, November 04, 2011 2:59:01 PM

Call this method from onCreateOptions()


private void setupSearchView(Menu menu)
{
    SearchView searchView = 
        (SearchView) menu.findItem(R.id.menu_search).getActionView();
    if (searchView == null)
    {
        this.reportBack(tag, "Failed to get search view");
        return;
    }
    //setup searchview
    SearchManager searchManager = 
        (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    ComponentName cn = 
        new ComponentName(this,SearchResultsActivity.class);
    SearchableInfo info = 
        searchManager.getSearchableInfo(cn);
    if (info == null)
    {
        this.reportBack(tag, "Failed to get search info");
        return;
    }

    searchView.setSearchableInfo(info);

    // Do not iconify the widget; expand it by default
    searchView.setIconifiedByDefault(false); 
}

satya - Thu Nov 29 2012 22:43:38 GMT-0500 (Eastern Standard Time)

How to enable actionbar in ICS

How to enable actionbar in ICS

Search for: How to enable actionbar in ICS

satya - Thu Nov 29 2012 22:46:07 GMT-0500 (Eastern Standard Time)

See this document on actionbar from google

See this document on actionbar from google

satya - Thu Nov 29 2012 22:46:52 GMT-0500 (Eastern Standard Time)

You do this


<manifest ... >
    <uses-sdk android:minSdkVersion="4"
              android:targetSdkVersion="11" />
    ...
</manifest>

satya - Thu Nov 29 2012 22:57:27 GMT-0500 (Eastern Standard Time)

This is only necessary if you misdkversion is older like 4 above

If it is 11 or higher you don't need to do that. actionbar is automatically enabled. A target version that is recent than the minsdkversion is a hint to android to gracefully fallback where possible but optimize it if later.