How to use Actionbar items with Viewpager + Fragments

后端 未结 1 825
渐次进展
渐次进展 2021-02-15 11:44

Im trying to figure out how to implement Actionbar items based on the Fragment that is being loaded inside my viewpager. My code is below and im just trying to figure out the be

相关标签:
1条回答
  • 2021-02-15 12:28

    Im trying to figure out how to implement Actionbar items based on the Fragment that is being loaded inside my viewpager.

    That happens automatically. Just have the fragments call setHasOptionsMenu(true), then implement onCreateOptionsMenu() and onOptionsItemSelected(). The Fragment*PagerAdapter will arrange to repopulate the action bar after a page change, to remove action bar items from the previous page and introduce action bar items from the newly-current page.

    Here is a sample project demonstrating having action bar items come and go, as only odd-numbered pages (for 1-based indexes, what the user sees) have action bar items.

    0 讨论(0)
提交回复
热议问题