Actionbar moving tab indicator

馋奶兔 提交于 2019-12-11 02:33:34

问题


I'm using ActionBar of AppCompact with tabs and ViewPager.
How can I implement moving (with the fragment) tabs indicator like in Onavo app?
I tried to use PagerTitleStrip but didn't succeed.


回答1:


There is a library called "PagerSlidingTabStrip" that does exactly what you want: https://github.com/astuetz/PagerSlidingTabStrip

Interactive paging indicator widget, compatible with the ViewPager from the Android Support Library.

Usage

Include the PagerSlidingTabStrip widget in your view. This should usually be placed adjacent to the ViewPager it represents.

<com.astuetz.viewpager.extensions.PagerSlidingTabStrip
   android:id="@+id/tabs"
   android:layout_width="match_parent"
    android:layout_height="48dip" />

In your onCreate method (or onCreateView for a fragment), bind the widget to the ViewPager.

 // Set the pager with an adapter
 ViewPager pager = (ViewPager) findViewById(R.id.pager);
 pager.setAdapter(new TestAdapter(getSupportFragmentManager()));

 // Bind the widget to the adapter
 PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
 tabs.setViewPager(pager);

(Optional) If you use an OnPageChangeListener with your view pager you should set it in the widget rather than on the pager directly.

 // continued from above
 tabs.setOnPageChangeListener(mPageChangeListener);


来源:https://stackoverflow.com/questions/20521368/actionbar-moving-tab-indicator

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