代码之家  ›  专栏  ›  技术社区  ›  Jaimin Modi

Android BottomView的定制

  •  0
  • Jaimin Modi  · 技术社区  · 4 年前

    [![我想要这样的底部栏][1][1]

    在android中使用以下库自定义底部选项卡栏: https://github.com/Droppers/AnimatedBottomBar

    它很容易使用,并提供许多动画。 但是,我不希望菜单文本内容显示在底部栏中。

    我只想在选中或未选中时显示图标。

    我怎样才能用这个库实现目标? 或者有什么方法可以实现这样的事情吗?

    0 回复  |  直到 4 年前
        1
  •  2
  •   Rajan Kali    4 年前

    我浏览了上面提到的库,它目前不支持这个功能,但我们可以调整代码,使其适用于您的用例,但要做到这一点,您需要将代码作为模块/文件夹而不是依赖项包含。

    要实现这一点,您需要遵循以下步骤

    • 你需要摆脱对生活的依赖 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"
    }
    
        2
  •  0
  •   Greeshma    4 年前

    如果您在回购协议的描述中看到,您将看到关于选项卡外观的一些属性

    加上这个 app:abb_selectedTabType = "icon" 添加到可能已经添加到xml中的代码中,如下所示

    <nl.joery.animatedbottombar.AnimatedBottomBar
            android:id="@+id/bottom_bar"
            android:background="#FFF"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:abb_selectedTabType="text"
            app:abb_indicatorAppearance="round"
            app:abb_indicatorMargin="16dp"
            app:abb_indicatorHeight="4dp"
            app:abb_tabs="@menu/tabs"
            app:abb_selectedTabType = "icon" 
            app:abb_selectedIndex="1" />
    
    推荐文章