一个漂亮的Tab实现:Android-NiceTab
jopen
9年前
一个漂亮的Tab实现一个ViewPager中不同页面之间的导航。支持badge, blur, and cross fade effect。
Usage
For a working implementation of this project see thedemo/folder.
-
Add the library as a project. or just
dependencies { compile 'me.amiee:nicetab:1.0.0' }
-
Include the NiceTabLayout widget in your layout. This should usually be placed above theViewPagerit represents.
<me.amiee.nicetab.NiceTabLayout xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="@dimen/tab_height" android:background="?colorPrimary" app:ntlDividerPaddingLeft="8dp" app:ntlDividerPaddingRight="8dp" app:ntlIndicatorHeight="2dp" app:ntlOverlayColor="#aa1a237e" app:ntlTabMode="both" app:ntlTextSize="@dimen/tab_title_text_size" app:ntlTextStyle="normal" app:ntlUnderlineHeight="1dp"/>
-
In youronCreatemethod (oronCreateViewfor a fragment), bind the widget to theViewPager.
// Initialize the ViewPager and set an adapter mViewPager = (ViewPager) view.findViewById(R.id.viewpager); mViewPager.setAdapter(new SampleFragmentPagerAdapter(getChildFragmentManager())); // Bind the tabs to the ViewPager mNiceTabLayout = (NiceTabLayout) view.findViewById(R.id.sliding_tabs); mNiceTabLayout.setViewPager(mViewPager);
-
(Optional) If you use anOnPageChangeListenerwith your view pager you should set it in the widget rather than on the pager directly.
// continued from above mNiceTabLayout.setOnPageChangeListener(mPageChangeListener);
-
(Optional) If your adapter implements the interfaceNiceTabLayout.IconTabProvideryou can add icon to tab view/s. The tab view should be aTextvieworImageViewthe icon will be used for textView's drawable top or imageView's image.