Background of the project
Project requirements, imitating Jingdong list sidebar UI, Androidx UI requirements, imitating Jingdong classification sidebar.
First of all, as a general developer, when encountering such UI needs, the first thing to do is to look for open source, hahaha~
Found an open source project VerticalTabLayout on github , thanks for open source ! This library can basically meet most of the side navigation bar needs. But this project has not been maintained for a long time (AndroidX is not supported, Kotlin syntax is not supported, and the tab page switching is too rough to meet the needs of UI designers) Based on this framework, a new set of sidebars has been developed Framework, and contribute it, I hope it can help everyone.
text
Not much to say, first post the renderings. Project address: https://github.com/JiaJie-xu1/VerticalTabLib
How To Use
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.JiaJie-xu1:VerticalTabLib:2.0.1'
}
Step 3. xml
<com.partner.tabtools.verticalTab.VerticalTabLayout
android:id="@+id/verticalTabLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#f7f7f7"
app:indicator_color="#64e4f2"
app:indicator_gravity="left"
app:tab_mode="scrollable"
app:tab_height="@dimen/dp55"/>
Step 4. Adapter method creation (kotlin writing)
adapter =object : TabAdapter {
override fun getIcon(position: Int): TabView.TabIcon? {
return null
}
override fun getBadge(position: Int): TabView.TabBadge? {
return null
}
override fun getBackground(position: Int): Int {
return resources.getColor(R.color.white)
}
override fun getTitle(position: Int): TabView.TabTitle {
return TabView.TabTitle.Builder()
.setContent(tabsTitle[position])
.setTextSize(DisplayUtil.getSR(13))
.setTextColor(0xFFcbcbcc.toInt(), 0xFF4a4a4a.toInt())
.build()
}
override fun getCount(): Int {
return tabsTitle.size
}
}
verticalTabLayout.setTabAdapter(adapter)
java writing
tablayout.setTabAdapter(new TabAdapter() {
@Override
public int getCount() {
return 0;
}
@Override
public TabView.TabBadge getBadge(int position) {
return null;
}
@Override
public TabView.TabIcon getIcon(int position) {
return null;
}
@Override
public TabView.TabTitle getTitle(int position) {
return null;
}
@Override
public int getBackground(int position) {
return 0;
}
});
按照自己的需要进行返回相应的值即可,不需要的返回0或者null
也可以选择使用SimpleTabAdapter,内部空实现了TabAdapter的所有方法
TabBadge、TabIcon、TabTitle使用build模式创建。
Any questions and bugs are welcome!