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 Jul 29, 2016
1 parent f0fd19f commit e54fa35
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.chenshixin.bottomnavigation

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.support.design.widget.CoordinatorLayout
import android.support.v4.view.ViewCompat
import android.support.v4.view.ViewPropertyAnimatorCompat
import android.support.v4.view.animation.LinearOutSlowInInterpolator
import android.util.AttributeSet
import android.view.LayoutInflater
Expand Down Expand Up @@ -104,6 +104,15 @@ class BottomNavigationBar(context: Context, attrs: AttributeSet) : FrameLayout(c
return this
}

/**
* Set background for badge
*/
fun setBadgeBackground(drawable: Drawable) {
tabs.map { tab ->
tab.setBadgeBackground(drawable)
}
}

interface OnTabSelectedListener {

fun onTabWillBeSelected(position: Int): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.chenshixin.bottomnavigation

import android.animation.ValueAnimator
import android.content.Context
import android.graphics.drawable.Drawable
import android.util.TypedValue
import android.view.Gravity
import android.view.LayoutInflater
Expand Down Expand Up @@ -49,6 +50,13 @@ class BottomNavigationTab(item: BottomNavigationItem, itemWidth: Int, val titleC
setCurrentTextColor(titleColorInactive)
}

/**
* Set background for badge
*/
fun setBadgeBackground(drawable: Drawable) {
bottom_navigation_bar_icon_badge.background = drawable
}

internal fun setBadgeNumber(number: Int?) {
if (number != null && number > 0) {
bottom_navigation_bar_icon_badge.text = "$number"
Expand Down

0 comments on commit e54fa35

Please sign in to comment.