How to use Actionbar items with Viewpager + Fragments

早过忘川 提交于 2019-12-03 12:47:02

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!