Your SlideShare is downloading. ×
Разработка приложений для Android Honeycomb: ActionBar & Fragments
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

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

1,931
views

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,931
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Android introduced fragments in Android 3.0 (API Level "Honeycomb"), primarily to support more dynamic and flexible UI designs on large screens, such as tablets. Because a tablet's screen is much larger than that of a mobile phone, there's more room to combine and interchange UI components A fragment should be a modular and reusable component in your application.
  • Transcript

    • 1. Alexey Ustenko programmer @ustav
    • 2. Разработка приложений для Android Honeycomb: ActionBar & Fragments
    • 3. ActionBar
    • 4. Режим совместимости
    • 5. Стандартный режим
    • 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. Анатомия - Home icon - Title - Navigation - Custom View placeholder - Action buttons
    • 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. ActionBar actionBar = this .getActionBar(); actionBar. setDisplayHomeAsUpEnabled( true ) ; Home as “Up”
    • 10. NAVIGATION_MODE_LIST NAVIGATION_MODE_TABS Navigation Mode
    • 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. Action Mode
    • 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. Fragments
    • 15. Жизненный цикл
    • 16. DialogFragment
    • 17. ListFragment
    • 18. PreferenceFragment
    • 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. 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. // 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. 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. 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. Фрагменты доступны с версии Android 1.6 (API level 4) при использовании пакета совместимости, который входит в Android SDK (android-support-v4.jar)
    • 25. http://developer.android.com

    ×