我浏览了上面提到的库,它目前不支持这个功能,但我们可以调整代码,使其适用于您的用例,但要做到这一点,您需要将代码作为模块/文件夹而不是依赖项包含。
要实现这一点,您需要遵循以下步骤
-
你需要摆脱对生活的依赖
implementation 'nl.joery.animatedbottombar:library:1.0.9'
-
清理项目以将其从缓存中删除
-
你可以克隆代码,添加
'library'
将代码中的文件夹作为Android模块,然后使用
implementation project(path: ':library')
完成上述步骤后,您可以根据需要修改代码。现在,对于您的用例,请务必替换
updateTabType
目前的方法
line#99
在…内
library/src/main/java/nl/joery/animatedbottombar/TabView.kt
将文件归档到下面
private fun updateTabType() {
animatedView = icon_layout
selectedAnimatedView = icon_layout //here we are forcing it use icon_layout for both views all the time
if (selectedAnimatedView.visibility == View.VISIBLE) {
animatedView.visibility = View.VISIBLE
selectedAnimatedView.visibility = View.INVISIBLE
} else {
animatedView.visibility = View.INVISIBLE
selectedAnimatedView.visibility = View.VISIBLE
}
bringViewsToFront()
}
此外,该库是根据麻省理工学院开放源码许可证授权的,因此您可以
很高兴免费更改自己的代码版本。
使现代化
还有,在
library
模块gradle,请删除对bintray的引用,这不是必需的
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0.9"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.61"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'com.google.android:flexbox:2.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.navigation:navigation-ui-ktx:2.3.1"
}