Successfully reported this slideshow.
Action BarKewang             1
1.App icon (android.R.id.home)2.View control3.Action buttons4.Action overflow                                 2
Action Bar wants to provideIdentifying the app brandConsistent navigationMake key actions                              3
Show Action Bar<uses-sdk android:minSdkVersion="11" /><application android:theme="@android:style/Theme.Holo" />API Level M...
Hide Action Bar    Manifest.xml (remove Action Bar)<applicationandroid:theme="@android:style/Theme.Holo.NoActionBar" />   ...
App Icon for Navigation● Go to the app "home" activity● Navigate "up" the apps structural hierarchy                       ...
App Icon for Navigation (Home)@Overridepublic boolean onOptionsItemSelected(MenuItem item) {  if (item.getItemId() == andr...
App Icon for Navigation (Up)           BACK navigation                               8
App Icon for Navigation (Up)                UP navigation                                9
App Icon for Navigation (Up)getActionBar().setDisplayHomeAsUpEnabled(true);                                               ...
Action Items               11
Action Items<item  android:actionViewClass="android.widget.SearchView"  android:icon="@drawable/icon_modify"  android:show...
Action Items<item  android:icon="@drawable/icon_setup"  android:showAsAction="never"  android:title="設定一"/><item  android:...
Action View@Overridepublic boolean onCreateOptionsMenu(Menu menu) {  getMenuInflater().inflate(R.menu.main, menu);    Sear...
Action Bar Custom ViewactionBarView =getLayoutInflater().inflate(R.layout.navigation, null);getActionBar().setCustomView(a...
Stylingboolean: android:windowActionBarOverlay       falsetrue                                          16
Stylingandroid:actionButtonStyleandroid:actionBarItemBackgroundandroid:itemBackgroundandroid:actionBarDividerandroid:actio...
ActionView             18
ActionView<item  android:id="@+id/search"  android:actionViewClass="android.widget.SearchView"  android:showAsAction="ifRo...
ActionViewpublic boolean onCreateOptionsMenu(Menu menu) {  getMenuInflater().inflate(R.menu.main, menu);    MenuItem item ...
Navigation             21
NavigationsetNavigationMode(int)•   ActionBar.NAVIGATION_MODE_STANDARD•   ActionBar.NAVIGATION_MODE_TABS•   ActionBar.NAVI...
NavigationSTANDARD                        23
NavigationTABS                    24
NavigationLIST                    25
Navigation - TABS implementationTab tab = getActionBar().newTab();tab.setText("這是TAB Name");tab.setIcon(getDrawable(R.draw...
Navigation - LIST implementationArrayAdapter<String> adapter = newArrayAdapter<String>(this, R.layout.simple_spinner_item,...
「    API 就是要無腦!                 」                 28
FragmentFramework• Action Bars style• Navigation mode• Fragments callback at CRUD• App Icon navigation mode• Swipe all fra...
Containerpublic abstract class Container {  public void addFragment(String, Fragment)  public void removeFragment(Fragment...
Containerpublic abstract class Container {  public boolean isSliding();  public int getNavigationMode();  public int getAp...
Navigationpublic interface ListNavigation {  public void setActionBar(ActionBar actionBar);  public int getActionBarLayout...
TODO• TODO standard navigation direction• TODO communication between fragments• TODO bulk fragments on creating• TODO hier...
34
Upcoming SlideShare
Loading in …5
×

Action bar

1,641 views

Published on

Published in: Technology, Art & Photos
  • Be the first to comment

Action bar

  1. 1. Action BarKewang 1
  2. 2. 1.App icon (android.R.id.home)2.View control3.Action buttons4.Action overflow 2
  3. 3. Action Bar wants to provideIdentifying the app brandConsistent navigationMake key actions 3
  4. 4. Show Action Bar<uses-sdk android:minSdkVersion="11" /><application android:theme="@android:style/Theme.Holo" />API Level MUST be 11 or greaterthemes android:windowActionBar="true", or theme MUST be Holo or its descendants 4
  5. 5. Hide Action Bar Manifest.xml (remove Action Bar)<applicationandroid:theme="@android:style/Theme.Holo.NoActionBar" /> at Activity getActionBar().hide(); 5
  6. 6. App Icon for Navigation● Go to the app "home" activity● Navigate "up" the apps structural hierarchy 6
  7. 7. App Icon for Navigation (Home)@Overridepublic boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { Intent intent = new Intent(this, Main.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); return true; }} add FLAG_ACTIVITY_CLEAR_TOP 7
  8. 8. App Icon for Navigation (Up) BACK navigation 8
  9. 9. App Icon for Navigation (Up) UP navigation 9
  10. 10. App Icon for Navigation (Up)getActionBar().setDisplayHomeAsUpEnabled(true); 10
  11. 11. Action Items 11
  12. 12. Action Items<item android:actionViewClass="android.widget.SearchView" android:icon="@drawable/icon_modify" android:showAsAction="ifRoom" android:title="@string/menu_settings"/><item android:icon="@drawable/icon_status" android:showAsAction="ifRoom|withText" android:title="設定二"/> MUST define title & id 12
  13. 13. Action Items<item android:icon="@drawable/icon_setup" android:showAsAction="never" android:title="設定一"/><item android:icon="@drawable/icon_manual" android:showAsAction="always" android:title="主設定"> <menu> <item android:title="密碼設定"/> <item android:title="檢核戶號"/> </menu></item> 13
  14. 14. Action View@Overridepublic boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); SearchView v = menu.findItem(R.id.set).getActionView(); v.setOnSearchClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(Main.this, "Search",Toast.LENGTH_SHORT).show(); } }); return true;} 14
  15. 15. Action Bar Custom ViewactionBarView =getLayoutInflater().inflate(R.layout.navigation, null);getActionBar().setCustomView(actionBarView);getActionBar().setDisplayShowCustomEnabled(true); 15
  16. 16. Stylingboolean: android:windowActionBarOverlay falsetrue 16
  17. 17. Stylingandroid:actionButtonStyleandroid:actionBarItemBackgroundandroid:itemBackgroundandroid:actionBarDividerandroid:actionMenuTextColorandroid:actionMenuTextAppearanceandroid:actionBarWidgetTheme 17
  18. 18. ActionView 18
  19. 19. ActionView<item android:id="@+id/search" android:actionViewClass="android.widget.SearchView" android:showAsAction="ifRoom|collapseActionView" android:title="Search"/> <item android:id="@+id/search" android:actionLayout="@layout/action_layout" android:showAsAction="ifRoom|collapseActionView" android:title="Search"/> 19
  20. 20. ActionViewpublic boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); MenuItem item = menu.findItem(R.id.search); View v = (View) item.getActionView(); // SDK 11+ item.setOnActionExpandListener(new OnActionExpandListener() { boolean onMenuItemActionExpand(MenuItem item) { return true; // trigger by item.expandActionView() } boolean onMenuItemActionCollapse(MenuItem item) { return true; // trigger by item.collapseActionView() } }); only SDK 14+ return true; 20}
  21. 21. Navigation 21
  22. 22. NavigationsetNavigationMode(int)• ActionBar.NAVIGATION_MODE_STANDARD• ActionBar.NAVIGATION_MODE_TABS• ActionBar.NAVIGATION_MODE_LIST 22
  23. 23. NavigationSTANDARD 23
  24. 24. NavigationTABS 24
  25. 25. NavigationLIST 25
  26. 26. Navigation - TABS implementationTab tab = getActionBar().newTab();tab.setText("這是TAB Name");tab.setIcon(getDrawable(R.drawable.icon_setup));tab.setTabListener(new TabListener() { void onTabUnselected(Tab, FragmentTransaction) {} void onTabSelected(Tab, FragmentTransaction) { // using tab.getPosition() to do something } void onTabReselected(Tab, FragmentTransaction) {}});getActionBar().addTab(tab); 26
  27. 27. Navigation - LIST implementationArrayAdapter<String> adapter = newArrayAdapter<String>(this, R.layout.simple_spinner_item,R.id.text1, new String[] { "aaa", "bbb" });adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);getActionBar().setListNavigationCallbacks(adapter, newOnNavigationListener() { boolean onNavigationItemSelected(int position, long id) { // using position to do something return true; }}); 27
  28. 28. 「 API 就是要無腦! 」 28
  29. 29. FragmentFramework• Action Bars style• Navigation mode• Fragments callback at CRUD• App Icon navigation mode• Swipe all fragments• Main fragment settings 29
  30. 30. Containerpublic abstract class Container { public void addFragment(String, Fragment) public void removeFragment(Fragment) public void showFragment(Fragment) public void hideFragment(Fragment) public void replaceFragment(String, Fragment) public void onFragmentAdded(FragmentProperty) public void onFragmentRemoved(FragmentProperty) public void onFragmentShown(FragmentProperty) public void onFragmentHidden(FragmentProperty) public void onFragmentReplaced(FragmentProperty)} 30
  31. 31. Containerpublic abstract class Container { public boolean isSliding(); public int getNavigationMode(); public int getAppIconMode(); public abstract Fragment getMainFragment(); public abstract String getMainFragmentName();} 31
  32. 32. Navigationpublic interface ListNavigation { public void setActionBar(ActionBar actionBar); public int getActionBarLayoutId(); public BaseAdapter getNavigationAdapter(); public interface StandardNavigation extends ListNavigation { public int getNavigationWidth(); public int getNavigationDirection(); }} ListNavigation for LIST StandardNavigation for STANDARD 32
  33. 33. TODO• TODO standard navigation direction• TODO communication between fragments• TODO bulk fragments on creating• TODO hierarchical fragments• TODO more generic• more... 33
  34. 34. 34

×