Q805699513 PagerSlidingTabStrip Save

一款android指示器TabLayout、PagerSlidingTabStrip,仿Boss直聘,带有红点未读提示

Project README

PagerSlidingTabStrip

一款android指示器TabLayout、PagerSlidingTabStrip,仿Boss直聘,带有红点未读提示

Example

   

Usage

Gradle

dependencies {
 //稳定版(推荐)没特殊需求建议使用官方TabLayout控件
 compile 'com.longsh:PagerSlidingTabStrip:1.0.0'
 //测试版
 compile 'com.longsh:PagerSlidingTabStrip:1.0.1'
}

使用

    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
    pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
    tabs.setViewPager(pager);
    //pager.setOffscreenPageLimit(6);
    //设置参数
    setTabsValue();
    
     //例:设置第三个tab小红点显示,item从0开始计算,true为显示,false为隐藏,默认为全部隐藏
      //tabs.setMsgToast(2, true);
      
    //MyPagerAdapter为普通的FragmentPagerAdapter
    public class MyPagerAdapter extends FragmentPagerAdapter {...略}
    

设置参数setTabsValue();

    private void setTabsValue() {
          DisplayMetrics dm = getResources().getDisplayMetrics();
          // 设置Tab底部选中的指示器Indicator的高度
          tabs.setIndicatorHeight(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2.5f, dm));
          // 设置Tab底部选中的指示器 Indicator的颜色
          tabs.setIndicatorColorResource(R.color.colorPrimary);
          //设置指示器Indicatorin是否跟文本一样宽,默认false
          tabs.setIndicatorinFollowerTv(false);
          //设置小红点提示,item从0开始计算,true为显示,false为隐藏,默认为全部隐藏
      //    tabs.setMsgToast(2, true);
          //设置红点滑动到当前页面自动消失,默认为true
          tabs.setMsgToastPager(true);
          //设置Tab标题文字的颜色
          //tabs.setTextColor(R.color.***);
          // 设置Tab标题文字的大小
          tabs.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 15, dm));
          // 设置选中的Tab文字的颜色
          tabs.setSelectedTextColorResource(R.color.colorPrimary);
          //设置Tab底部分割线的高度
          tabs.setUnderlineHeight(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1f, dm));
          //设置Tab底部分割线的颜色
          //tabs.setUnderlineColorResource(R.color.colorGray);
          // 设置点击某个Tab时的背景色,设置为0时取消背景色tabs.setTabBackground(0);
      //        tabs.setTabBackground(R.drawable.bg_tab);
          tabs.setTabBackground(0);
          // 设置Tab是自动填充满屏幕的
          tabs.setShouldExpand(true);

          //设置标签是否需要滑动,多个tab文字不够一屏显示的时候使用,后面会改成内部自动判断-----------------------------------------//todo
         //必须设置,1.0.0不需要设置这行
         tabs.setTabsScroll(true);
   }

XML布局代码

 <com.longsh.longshlibrary.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        />
        
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

如果你需要监听viewpager的滑动状态setOnPageChangeListener

    tabs.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
           //if (position == 2) {
                //手动隐藏第二个小红点,tabs.setMsgToastPager(false);该方法为false时才需要手动隐藏。
                //tabs.setMsgToast(2, false);
           //}
        }
        
        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

使用参考类

使用参考类

Version: 1.0.1

//修复1.0.0文字自适应宽度  新增tabs.setTabsScroll(true);设置标签是否需要滑动,多个tab文字不够一屏显示的时候使用 todo //后续有时间会弄成内部自动判断。

Version: 1.0.0

 有其他需求可以给我提Issues,我在res/layout/布局里面设置了android:maxLength="5",限制每个tab最多显示5个字符,如果超过了5个字符的请下载源码去掉这行。

Thanks

License


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Open Source Agenda is not affiliated with "Q805699513 PagerSlidingTabStrip" Project. README Source: q805699513/PagerSlidingTabStrip
Stars
158
Open Issues
2
Last Commit
6 years ago
License

Open Source Agenda Badge

Open Source Agenda Rating