有没有办法将ViewPager中的每个片段与某个导航选项卡相关联? 因此,当我们向右/向左翻转时,右侧选项卡将突出显示。
谢谢。
Is there any way to associate each fragment in the ViewPager with a certain navigation tab? So when we flip right/left ,the right tab will be highlighted.
Thank you.
最满意答案
使用Material Design支持库中的TabLayout。
请参阅介绍该库的博客文章中的“选项卡”段落:
但是,如果您使用ViewPager在选项卡之间进行水平分页,则可以直接从PagerAdapter的getPageTitle()创建选项卡,然后使用setupWithViewPager()将两者连接在一起。 这可确保选项卡选择事件更新ViewPager,页面更改将更新选定的选项卡。
Use TabLayout from the Material Design support library.
See the "Tabs" paragraph in the blog post that introduces the library:
However, if you are using a ViewPager for horizontal paging between tabs, you can create tabs directly from your PagerAdapter’s getPageTitle() and then connect the two together using setupWithViewPager(). This ensures that tab selection events update the ViewPager and page changes update the selected tab.
更多推荐
发布评论