ActionBar :
ActionBar , is one of the coolest feature newly available in honey com ui.Allows user to customize title bar.
By ActionBar ,frequently used action made available to user without searching.
3 forms of Action Bar:
- Tabbed Action Bar
- List Action Bar
- Standard Action Bar
Tabbed Action Bar:
Options appear in tab form.In below screen shot we have two tabs namely Tab1 & tab2.
Code snippet :
ActionBar bar = this.getActionBar();
bar.setTitle("Tabbed Activity");
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
TabListener tabListener = new TabListener() {
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
System.out.println("Tab Unselected("+tab.getText());
}
public void onTabSelected(Tab tab, FragmentTransaction ft) {
System.out.println("Tab Selected"+tab.getText());
}
public void onTabReselected(Tab tab, FragmentTransaction ft) {
System.out.println("Tab Reselected"+tab.getText());
}
};
// Create tabs
Tab tab1 = bar.newTab();
tab1.setText("Tab1");
tab1.setTabListener(tabListener);
bar.addTab(tab1);
Tab tab2 = bar.newTab();
tab2.setText("Tab2");
tab2.setTabListener(tabListener);
bar.addTab(tab2);
Standard Action Bar:
Options appear in right corner as quick launch icons.In below screen shot we have two Quick launch icon.
Code Snippet :
private void createmenuActionBar()
{
ActionBar bar = this.getActionBar();
bar.setTitle("menu");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
// action should be handled here
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
return super.onOptionsItemSelected(item);
}
menu.xml :(res/menu/menu.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/group1">
<item android:id="@+id/item1" android:title="@string/menu1"
android:icon="@drawable/creep001" android:showAsAction="ifRoom"></item>
<item android:id="@+id/item2" android:title="@string/menu2"
android:showAsAction="ifRoom" android:icon="@drawable/creep002"></item>
</group>
</menu>
List Action Bar:
Options appear in list form.In below screen shot we have two options blackberry & android
In Activity , specify form
ActionBar bar = this.getActionBar();
bar.setTitle("List");
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
menu.xml(res/menu/menu.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/group1">
<item android:id="@+id/item1" android:title="@string/menu1"
android:icon="@drawable/creep001" ></item>
<item android:id="@+id/item2" android:title="@string/menu2"
android:icon="@drawable/creep002"></item>
</group>
</menu>
No comments:
Post a Comment