Skip to content

Commit

Permalink
Add interface to set background for badge
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshixin committed Sep 20, 2016
1 parent 9aa70c2 commit 361c8b6
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 361c8b6

Please sign in to comment.