5 Star 0 Fork 0

佰钧成开源官方组织 / AdvancedPagerSlidingTabStrip

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

AdvancedPagerSlidingTabStrip

介绍

AdvancedPagerSlidingTabStrip是一种HarmonyOS平台的导航控件,完美兼容HarmonyOS自带库和兼容库的PageSlider组件,最低支持HarmonyOS 4。 输入图片说明

特技

  • 支持Tab小圆点以及数量显示和隐藏
  • 支持自定义Tab View
  • 支持使用Bitmap、Drawable和本地resId来显示Tab图标
  • 支持自由设置小圆点、tab大小和位置等设置
  • 支持实现如:微博等不均匀Tab的APP风格,并支持滑动

效果图: 输入图片说明 输入图片说明 输入图片说明 输入图片说明 输入图片说明

安装教程

1.进入代码下载,下载源码后,导入到DevEco Studio 2.直接运行代码,可以了解demo代码所展示的部分功能

集成方法说明

方案一:本地源码集成,用户可以进行定制化修改 1.将library文件夹拷贝至工程目录 2.修改工程下的settings.gradle,如下添加对library模块的依赖:

include ':entry', ':Library'

3.在工程下引入导入的模块的依赖,以sample模块举例,需要修改sample模块下的build.gradle文件中添加依赖:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
    implementation project(path: ':Library')
    testImplementation 'junit:junit:4.13'
    ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100'
}

方案二:本地har包集成。 1.编译此工程,将library文件夹build目录下生成的har包拷贝到工程lib文件夹内: 输入图片说明 2.在entry的gradle内添加如下代码

implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])

方案三:远程仓库依赖

implementation ‘com.gitee.baijuncheng-open-source:Advancedpagerslidingtabstrip:1.0.0’

##用法

基本AdvancedPagerPagerSlidingTabStrip:

在需要添加的界面xml中添加组件和PageSlider

    <com.lhh.apst.library.AdvancedPagerSlidingTabStrip
        ohos:id="$+id:tabs"
        ohos:width="match_parent"
        ohos:height="42vp"
        ohos:background_element="#ff303032"
        app:apTabTextSize = "13fp"
        app:apTabTextColor = "#adadad"
        app:apTabBackground = "#00000000"
        app:apTabIndicatorColor = "#ff5959"
        app:apTabUnderlineColor = "#1A000000"
        app:apTabDividerColor = "#00000000"
        app:apTabShouldExpand = "false"
        app:apTabPaddingLeftRight = "8vp"
        app:apTabDrawMode = "1"
        app:apTabTextSelectColor = "#ff5959"/>

在代码中find该组件,并且设置Proiver和PageSlider。

PageSlider pager = (PageSlider) findComponentById(ResourceTable.Id_vp_main);
pager.setProvider(provider);

AdvancedPagerSlidingTabStrip tabs = (AdvancedPagerSlidingTabStrip) findComponentById(ResourceTable.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+”);

Tab显示模式

基本Provider显示

1.纯文本显示

通过实现Provider内的getPageTitle()接口即可显示纯文本情况的效果。

2.图文显示

通过将Provider实现AdvancedPagerSlidingTabStrip.IconTabProvider接口,并实现其中的getPageIcon(展示未选中的图片)、getPageSelectIcon(展示选中的图片)和getPageIconText(展示的文本)方法即可显示图文效果。

其中getPageIcon(展示未选中的图片)和getPageSelectIcon方法可以通过改变方法返回值来显示不同类型的图片,可以选择的返回值为Pixemap、Element和ResId。

3.自定义图片Component显示

通过将Provider实现AdvancedPagerSlidingTabStrip.ViewTabProvider接口,并实现其中的onSelectIconView(选中的自定义图片Component)、onIconView(未选中的自定义图片Component)和getPageIconText(文本)方法即可。

需要注意的是,onSelectIconView和onIconView两个方法的返回值均为Component,并会回调回上一次使用的Component缓存对象,你可以通过判断返回的Component是否为null来决定是否新建Component对象。(PS:不判断缓存将导致你每次调用都会创建新的Component对象。)

你可以直接创建并返回Image对象,也可以返回其他Component子类,该模式可以用于显示网络图片,需要注意的是你需要手动给Component添加LayoutConfig来控制其大小,并只能使用DependentLayout.LayoutConfig,具体实现方式可以查看Demo。

自定义Tab

我知道以上模式可能并不能完全满足需求,有时候可能我们需要的是更复杂的Tab,所以添加自定义tab来满足各种各样的需求。

当前自定义tab被封装到另一个tab类中,通过使用CustomPagerSlidingTabStrip控件来实现,该控件的所有使用方法和AdvancedPagerSlidingTabStrip一致。

通过将Provider实现CustomPagerSlidingTabStrip.CustomTabProvider并实现其中getSelectTabView(选中的Component)和getDisSelectTabView(未选中的Component)方法来实现自定义Tab,两个方法同样会回调上一次使用的Component缓存对象。具体实现方式可以查看Demo。

拓展的Provider显示设置

有时候我们不使用自定义Component显示模式又想调整现有的Tab,比如设置小圆点位置、tab大小和间距等来满足原有就可以实现的需求。

AdvancedPagerSlidingTabStrip提供了几个Provider来实现这些功能,你可以通过将你的Provider实现定制的接口方法来实现,具体可以查看demo中的WeiboTabActivity.java。

AdvancedPagerSlidingTabStrip.LayoutProvider 通过将Provider实现AdvancedPagerSlidingTabStrip.LayoutProvider可以实现对Tab以及内容icon的Layout设置。

public float getPageWeight(int position); 该方法用于设置每个pageTab在整个tabs中的权重。

public int[] getPageRule(int position); 该方法用于设置每个tab的相对位置,如将tab设置为靠左:return new int[]{ RelativeLayout.ALIGN_PARENT_LEFT};。

public Margins getPageMargins(int position); 该方法用于设置每个tab的间距大小,如将tab设置为距离左边距30px:return new Margins(30,0,0,0);。

AdvancedPagerSlidingTabStrip.TipsProvider 通过将Provider实现AdvancedPagerSlidingTabStrip.TipsProvider可以实现对小圆点的设置。

public int[] getTipsRule(int position); 该方法用于设置小圆点的相对位置。

public Margins getTipsMargins(int position); 该方法用于设置小圆点在tab中的间距大小。

public Drawable getTipsDrawable(int position); 该方法用于设置小圆点的背景,默认为红色圆角图。

XML样式参数

  • apTabIndicatorColor 导航条的颜色
  • apTabUnderlineColor Tab底部下划线的颜色
  • apTabDividerColor 每个Tab之间的分割线颜色
  • apTabstabTextSelectColor 被选中的Tab的文本字体颜色
  • apTabIndicatorHeight 导航条的高度
  • apTabUnderlineHeight Tab底部下划线的高度
  • apTabDividerPadding Tab分割线的padding
  • apTabPaddingLeftRight 每个Tab的左右padding
  • apTabPaddingTopBottom 每个Tab的上下padding
  • apTabScrollOffset 选中tab的滑动offset
  • apTabBackground tab的背景
  • apTabShouldExpand 伸缩情况,如果为真,每个tab都是相同的weight,默认是false
  • apTabTextAllCaps Tab的文字是否为全部大写,如果是true就全部大写,默认为true
  • apTabTextSelectColor 你所选择的那个tab的颜色
  • apTabDrawMode 绘制模式,text或者normal,用于是否将下划线绘制为跟随TextView

##License 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.

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS

简介

暂无描述 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/baijuncheng-open-source/advanced-pager-sliding-tab-strip.git
git@gitee.com:baijuncheng-open-source/advanced-pager-sliding-tab-strip.git
baijuncheng-open-source
advanced-pager-sliding-tab-strip
AdvancedPagerSlidingTabStrip
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891