From 361c8b60f0d950c15b922640f1a422a773130578 Mon Sep 17 00:00:00 2001 From: chenshixin Date: Tue, 20 Sep 2016 14:49:57 +0800 Subject: [PATCH] Add interface to set background for badge --- .../com/chenshixin/bottomnavigation/BottomNavigationBar.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bottom-navigation/src/main/java/com/chenshixin/bottomnavigation/BottomNavigationBar.kt b/bottom-navigation/src/main/java/com/chenshixin/bottomnavigation/BottomNavigationBar.kt index f043229..9e94ad8 100644 --- a/bottom-navigation/src/main/java/com/chenshixin/bottomnavigation/BottomNavigationBar.kt +++ b/bottom-navigation/src/main/java/com/chenshixin/bottomnavigation/BottomNavigationBar.kt @@ -28,6 +28,7 @@ class BottomNavigationBar(context: Context, attrs: AttributeSet) : FrameLayout(c var backgroundColor: Int? = null var onTabSelectedListener: OnTabSelectedListener? = null var selectedPosition = 0 + var badgeBgDrawable: Drawable? = null /** * Inactive title color res id @@ -80,6 +81,9 @@ class BottomNavigationBar(context: Context, attrs: AttributeSet) : FrameLayout(c val tabWidth = getItemWidth() items.mapIndexed { index, item -> val tab = BottomNavigationTab(item, tabWidth, titleColorInactive, titleColorActive, context) + if (badgeBgDrawable != null) { + tab.setBadgeBackground(badgeBgDrawable!!) + } tab.position = index tab.setOnClickListener { view -> val newPosition = (view as BottomNavigationTab).position @@ -98,6 +102,7 @@ class BottomNavigationBar(context: Context, attrs: AttributeSet) : FrameLayout(c tabs.add(tab) bottom_navigation_bar_item_container.addView(tab) } + } internal fun setCurrentTab(index: Int) { @@ -135,6 +140,7 @@ class BottomNavigationBar(context: Context, attrs: AttributeSet) : FrameLayout(c * Set background for badge */ fun setBadgeBackground(drawable: Drawable) { + badgeBgDrawable = drawable tabs.map { tab -> tab.setBadgeBackground(drawable) }