Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BottomNavigationView Custom Item Image

I wanna to set a custom image to "Profile" item in the BottomNavigationView as the user is logged in. I have user's image URL.

This is the suggested design

enter image description here

like image 727
Amr Barakat Avatar asked Jan 30 '23 09:01

Amr Barakat


1 Answers

I used this code for make it works. (Kotlin)

navigation is the BottomNavigationView

val menu = navigation.menu
val menuItem = menu.findItem(R.id.my_account)
Glide.with(this)
        .asBitmap()
        .load("https://my_account_image_url")
        .apply(RequestOptions
                .circleCropTransform()
                .placeholder(R.drawable.ic_avatar))
        .into(object : SimpleTarget<Bitmap>() {
            override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                menuItem?.icon = BitmapDrawable(resources, resource)
            }
        })
like image 142
Key HeHa Avatar answered Jan 31 '23 23:01

Key HeHa