adding an option to change the bottom navigation bar drawable

This commit is contained in:
tibbi 2022-12-25 20:45:50 +01:00
parent 7f288cc10b
commit 9ffc3ac4d1
2 changed files with 16 additions and 13 deletions

View file

@ -1038,13 +1038,17 @@ fun Context.getPhoneNumberTypeText(type: Int, label: String): String {
}
}
fun Context.updateBottomTabItemColors(view: View?, isActive: Boolean) {
fun Context.updateBottomTabItemColors(view: View?, isActive: Boolean, drawable: Drawable? = null) {
val color = if (isActive) {
getProperPrimaryColor()
} else {
getProperTextColor()
}
if (drawable != null) {
view?.findViewById<ImageView>(R.id.tab_item_icon)?.setImageDrawable(drawable)
}
view?.findViewById<ImageView>(R.id.tab_item_icon)?.applyColorFilter(color)
view?.findViewById<TextView>(R.id.tab_item_label)?.setTextColor(color)
}

View file

@ -5,17 +5,16 @@ import com.google.android.material.tabs.TabLayout
fun TabLayout.onTabSelectionChanged(
tabUnselectedAction: ((inactiveTab: TabLayout.Tab) -> Unit)? = null,
tabSelectedAction: ((activeTab: TabLayout.Tab) -> Unit)? = null
) =
setOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
tabSelectedAction?.invoke(tab)
}
) = setOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
tabSelectedAction?.invoke(tab)
}
override fun onTabUnselected(tab: TabLayout.Tab) {
tabUnselectedAction?.invoke(tab)
}
override fun onTabUnselected(tab: TabLayout.Tab) {
tabUnselectedAction?.invoke(tab)
}
override fun onTabReselected(tab: TabLayout.Tab) {
tabSelectedAction?.invoke(tab)
}
})
override fun onTabReselected(tab: TabLayout.Tab) {
tabSelectedAction?.invoke(tab)
}
})