1.在项目根目录下的build.gradle文件中,
allprojects {
repositories {
maven {
url 'https://s01.oss.sonatype.org/content/repositories/releases/'
}
}
}
2.在entry模块的build.gradle文件中,
dependencies {
implementation('com.gitee.chinasoft_ohos:AdvancedPagerSlidingTabStrip:1.0.0')
......
}
在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
在 layout 文件中:
<com.lhh.apst.library.AdvancedPagerSlidingTabStrip
ohos:id="$+id:tabs"
ohos:height="42vp"
ohos:width="match_parent"
ohos:match_viewport="false"
ohos:background_element="$graphic:tab_bg_normal"
app:apTabBackground="$graphic:tab_bg_normal"
app:apTabIndicatorColor="$color:home_bar_text_push"
app:apTabUnderlineColor="#1A000000"
app:apTabDividerColor="#00000000"
app:apTabShouldExpand="false"
app:apTabPaddingLeftRight="8vp"
app:apTabTextSelectColor="$color:home_bar_text_push"
app:apTabTextSize="13"
app:apTabTextColor="$color:textnormal"
app:apTabDrawMode="1"
app:apTabIndicatorHeight="10"/>
在代码中find该组件,并且设置provider和PageSlider。
PageSlider pager = (PageSlider) findViewById(R.id.pager);
pager.setProvider(new MySlidePagerProvider(this));
AdvancedPagerSlidingTabStrip tabs = (AdvancedPagerSlidingTabStrip) findViewById(R.id.tabs);
tabs.setViewPager(pager);
AdvancedPagerSlidingTabStrip支持绑定OnPageChangeListener,并且不影响使用效果。
tabs.setOnPageChangeListener(mPageChangeListener);
通过调用AdvancedPagerSlidingTabStrip的showDot(int index)和hideDot(int index)来显示或者隐藏Tab上的小圆点,index代表需要显示和隐藏的tab序列位置(0 ~ N)。
通过调用showDot(int index,String txt)方法可以显示小圆点文字,并同样通过hideDot来隐藏。如:
tabs.showDot(0, “99+”);
基本Adapter显示
1.纯文本显示
通过实现Provider内的getPageTitle()接口即可显示纯文本情况的效果。
2.图文显示
通过将Provider实现AdvancedPagerSlidingTabStrip.IconTabProvider接口,并实现其中的getPageIcon(展示未选中的图片)、getPageSelectIcon(展示选中的图片)和getPageIconText(展示的文本)方法即可显示图文效果。
其中getPageIcon(展示未选中的图片)和getPageSelectIcon方法可以通过改变方法返回值来显示不同类型的图片,可以选择的返回值为Component、Element和本地resId。
3.自定义图片View显示
通过将Provider实现AdvancedPagerSlidingTabStrip.ViewTabProvider接口,并实现其中的onSelectIconView(选中的自定义图片View)、onIconView(未选中的自定义图片View)和getPageIconText(文本)方法即可。
需要注意的是,onSelectIconView和onIconView两个方法的返回值均为Component,并会回调回上一次使用的Component缓存对象,你可以通过判断返回的Component是否为null来决定是否新建Component对象 。
自定义Tab
我知道以上模式可能并不能完全满足需求,有时候可能我们需要的是更复杂的Tab,所以添加自定义tab来满足各种各样的需求。
当前自定义tab被封装到另一个tab类中,通过使用CustomPagerSlidingTabStrip控件来实现,该控件的所有使用方法和AdvancedPagerSlidingTabStrip一致。
拓展的Provider显示设置
有时候我们不使用自定义Component显示模式又想调整现有的Tab,比如设置小圆点位置、tab大小和间距等来满足原有就可以实现的需求。
AdvancedPagerSlidingTabStrip提供了几个Provider来实现这些功能,你可以通过将你的Provider实现定制的接口方法来实现,具体可以查看demo中的WeiboTabAbility.java。
AdvancedPagerSlidingTabStrip.LayoutProvider
通过将Adapter实现AdvancedPagerSlidingTabStrip.LayoutProvider可以实现对Tab以及内容icon的Layout设置。
public float getPageWeight(int position);
该方法用于设置每个pageTab在整个tabs中的权重。
public int[] getPageRule(int position);
该方法用于设置每个tab的相对位置。
public Margins getPageMargins(int position);
该方法用于设置每个tab的间距大小,如将tab设置为距离左边距30:return new Margins(30,0,0,0);
AdvancedPagerSlidingTabStrip.TipsProvider
通过将Adapter实现AdvancedPagerSlidingTabStrip.TipsProvider可以实现对小圆点的设置。
public int[] getTipsRule(int position);
该方法用于设置小圆点的相对位置。
public Margins getTipsMargins(int position);
该方法用于设置小圆点在tab中的间距大小。
public Element getTipsDrawable(int position);
该方法用于设置小圆点的背景,默认为红色圆角图。
配置
apTabIndicatorColor
导航条的颜色apTabUnderlineColor
Tab底部下划线的颜色apTabDividerColor
每个Tab之间的分割线颜色apTabstabTextSelectColor
被选中的Tab的文本字体颜色apTabIndicatorHeight
导航条的高度apTabUnderlineHeight
Tab底部下划线的高度apTabDividerPadding
Tab分割线的paddingapTabPaddingLeftRight
每个Tab的左右paddingapTabPaddingTopBottom
每个Tab的上下paddingapTabScrollOffset
选中tab的滑动offsetapTabBackground
tab的背景apTabShouldExpand
伸缩情况,如果为真,每个tab都是相同的weight,默认是falseapTabTextAllCaps
Tab的文字是否为全部大写,如果是true就全部大写,默认为trueapTabTextSelectColor
你所选择的那个tab的颜色apTabDrawMode
绘制模式,text或者normal,用于是否将下划线绘制为跟随TextViewCodeCheck代码测试无异常
CloudTest代码测试无异常
病毒安全检测通过
当前版本demo功能与原组件基本无差异
Copyright 2016 LinHongHong
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.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型