Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Commit

Permalink
add set unselected icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Mystery00 committed Jul 29, 2018
1 parent 4fe529e commit 7f35371
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@ package vip.mystery0.bottomTabView

import androidx.annotation.DrawableRes

data class BottomTabItem(
val name: String,
@DrawableRes
val icon: Int
) {
class BottomTabItem {
var name: String
@DrawableRes
var selectedIcon = 0
@DrawableRes
var unSelectedIcon = 0
var isChecked = false

constructor(name: String, @DrawableRes icon: Int) {
this.name = name
this.selectedIcon = icon
this.unSelectedIcon = icon
}

constructor(name: String, selectedIcon: Int, unSelectedIcon: Int) {
this.name = name
this.selectedIcon = selectedIcon
this.unSelectedIcon = unSelectedIcon
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ class BottomTabView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) :

private fun drawDrawable(bottomTabItem: BottomTabItem): Drawable? {
if (!bottomTabItem.isChecked) {
val drawable = ContextCompat.getDrawable(context, bottomTabItem.icon)!!
val drawable = ContextCompat.getDrawable(context, bottomTabItem.unSelectedIcon)!!
DrawableCompat.setTint(drawable.mutate(), config.unSelectedColor)
return drawable
}
val size = DensityTools.dp2px(context, config.itemIconSize)
val drawable = ContextCompat.getDrawable(context, bottomTabItem.icon)!!
val drawable = ContextCompat.getDrawable(context, bottomTabItem.selectedIcon)!!
val bitmap = Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
Expand Down

0 comments on commit 7f35371

Please sign in to comment.