Your SlideShare is downloading. ×
0
Alexey Ustenko programmer @ustav
Разработка приложений для Android Honeycomb: ActionBar & Fragments
ActionBar
Режим совместимости
Стандартный режим
< manifest   xmlns:android = &quot;http://schemas.android.com/apk/res/android&quot; package = &quot;com.example.helloworld...
Анатомия - Home icon - Title - Navigation - Custom View placeholder - Action buttons
@Override public   boolean   onOptionsItemSelected(MenuItem item)  { switch  (item.getItemId()) { case   android.R.id. hom...
ActionBar actionBar =  this .getActionBar(); actionBar. setDisplayHomeAsUpEnabled( true ) ; Home as “Up”
NAVIGATION_MODE_LIST NAVIGATION_MODE_TABS Navigation Mode
<? xml   version = &quot;1.0&quot;   encoding = &quot;utf-8&quot; ?> < menu   xmlns:android = &quot;http://schemas.android...
Action Mode
getActivity().startActionMode ( new  Callback() { @Override public   boolean  onPrepareActionMode(ActionMode mode, Menu me...
Fragments
Жизненный цикл
DialogFragment
ListFragment
PreferenceFragment
<? xml   version = &quot;1.0&quot;   encoding = &quot;utf-8&quot; ?> < LinearLayout   xmlns:android = &quot;http://schemas...
FragmentManager fragmentManager = getFragmentManager( ); FragmentTransaction fragmentTransaction = fragmentManager.beginTr...
// Create new fragment and transaction Fragment newFragment =  new  ExampleFragment(); FragmentTransaction transaction = g...
Communicating with the Activity View listView = getActivity().findViewById(R.id. list); Tab2Fragment fragment = (Tab2Fragm...
Custom action buttons for Fragment public   class  Tab2Fragment  extends  Fragment { @Override public  View onCreateView(L...
Фрагменты доступны с версии Android 1.6 (API level 4)  при использовании пакета совместимости,  который входит в Android S...
http://developer.android.com
Upcoming SlideShare
Loading in...5
×

Разработка приложений для Android Honeycomb: ActionBar & Fragments

1,970

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,970
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Android introduced fragments in Android 3.0 (API Level &amp;quot;Honeycomb&amp;quot;), primarily to support more dynamic and flexible UI designs on large screens, such as tablets. Because a tablet&apos;s screen is much larger than that of a mobile phone, there&apos;s more room to combine and interchange UI components A fragment should be a modular and reusable component in your application.
  • Transcript of "Разработка приложений для Android Honeycomb: ActionBar & Fragments"

    1. 1. Alexey Ustenko programmer @ustav
    2. 2. Разработка приложений для Android Honeycomb: ActionBar & Fragments
    3. 3. ActionBar
    4. 4. Режим совместимости
    5. 5. Стандартный режим
    6. 6. < manifest xmlns:android = &quot;http://schemas.android.com/apk/res/android&quot; package = &quot;com.example.helloworld&quot; android:versionCode = &quot;1&quot; android:versionName = &quot;1.0&quot; > < uses-sdk android:minSdkVersion = &quot;4&quot; android:targetSdkVersion = &quot;11&quot; /> < application . .. > ... </ application > </ manifest > Включить отображение ActionBar
    7. 7. Анатомия - Home icon - Title - Navigation - Custom View placeholder - Action buttons
    8. 8. @Override public 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); } } Home icon
    9. 9. ActionBar actionBar = this .getActionBar(); actionBar. setDisplayHomeAsUpEnabled( true ) ; Home as “Up”
    10. 10. NAVIGATION_MODE_LIST NAVIGATION_MODE_TABS Navigation Mode
    11. 11. <? xml version = &quot;1.0&quot; encoding = &quot;utf-8&quot; ?> < menu xmlns:android = &quot;http://schemas.android.com/apk/res/android&quot; > < item android:id = &quot;@+id/menu_search&quot; android:title = &quot;Search&quot; android:icon = &quot;@drawable/ic_menu_search&quot; android:showAsAction = &quot;ifRoom&quot; android:actionLayout = &quot;@layout/searchview&quot; /> </ menu > <? xml version = &quot;1.0&quot; encoding = &quot;utf-8&quot; ?> < menu xmlns:android = &quot;http://schemas.android.com/apk/res/android&quot; > < item android:id = &quot;@+id/menu_search&quot; android:title = &quot;Search&quot; android:icon = &quot;@drawable/ic_menu_search&quot; android:showAsAction = &quot;ifRoom&quot; android:actionViewClass = &quot;android.widget.SearchView&quot; /> </ menu > Action Layout
    12. 12. Action Mode
    13. 13. getActivity().startActionMode ( new Callback() { @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false ; } @Override public void onDestroyActionMode(ActionMode mode) { } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false ; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false ; } }); Action Mode code example
    14. 14. Fragments
    15. 15. Жизненный цикл
    16. 16. DialogFragment
    17. 17. ListFragment
    18. 18. PreferenceFragment
    19. 19. <? xml version = &quot;1.0&quot; encoding = &quot;utf-8&quot; ?> < LinearLayout xmlns:android = &quot;http://schemas.android.com/apk/res/android&quot; android:orientation = &quot;horizontal&quot; android:layout_width = &quot; match_parent &quot; android:layout_height = &quot; match_parent &quot; > < fragment android:name = &quot;com.example.news.ArticleListFragment&quot; android:id = &quot;@+id/list&quot; android:layout_weight = &quot;1&quot; android:layout_width = &quot;0dp&quot; android:layout_height = &quot; match_parent &quot; /> < fragment android:name = &quot;com.example.news.ArticleReaderFragment&quot; android:id = &quot;@+id/viewer&quot; android:layout_weight = &quot;2&quot; android:layout_width = &quot;0dp&quot; android:layout_height = &quot; match_parent &quot; /> </ LinearLayout > Add a Fragment in XML
    20. 20. FragmentManager fragmentManager = getFragmentManager( ); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); ExampleFragment fragment = new ExampleFragment (); fragmentTransaction.add(R.id.fragment_container, fragment); fragmentTransaction.commit(); Add a Fragment in code
    21. 21. // Create new fragment and transaction Fragment newFragment = new ExampleFragment(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack( null ); // Commit the transaction transaction.commit(); Fragment transactions
    22. 22. Communicating with the Activity View listView = getActivity().findViewById(R.id. list); Tab2Fragment fragment = (Tab2Fragment) getFragmentManager().findFragmentById(R.id.tab2); From Fragment to Activity From Activity (of another Fragment) to Fragment Tab2Fragment fragment = (Tab2Fragment) getFragmentManager().findFragmentByTag( &quot;tab2&quot; );
    23. 23. Custom action buttons for Fragment public class Tab2Fragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle state) { View view = inflater.inflate(R.layout. tab2 , null ); setHasOptionsMenu( true ); return view; } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu. tab2_menu , menu); } }
    24. 24. Фрагменты доступны с версии Android 1.6 (API level 4) при использовании пакета совместимости, который входит в Android SDK (android-support-v4.jar)
    25. 25. http://developer.android.com
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×