一個漂亮的Tab實現:Android-NiceTab

jopen 9年前發布 | 29K 次閱讀 Android開發 移動開發 Android-NiceTab

一個漂亮的Tab實現一個ViewPager中不同頁面之間的導航。支持badge, blur, and cross fade effect。

NiceTab Demo Gif

Usage

For a working implementation of this project see thedemo/folder.

  1. Add the library as a project. or just

     dependencies {
         compile 'me.amiee:nicetab:1.0.0' }
  2. 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"/>
  3. 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);
  4. (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);
  5. (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.


項目主頁:http://www.baiduhome.net/lib/view/home/1432884581707

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!