Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I wanted to load image from url into bottomnavigationview's menu item icon. same like instagram we wanted to show profile image in one of our menu which might change while switching from different available profiles. Currently, I am trying below code but it does not load image every time.

val menu = mViewDataBinding?.bnvNavigation?.menu
    val menuItem = menu?.findItem(R.id.menu_profile)

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        menuItem?.setIconTintList(null)
        menuItem?.setIconTintMode(null)
    }


    Glide.with(this)
        .asBitmap()
        .load(profilePic)
        .apply(
            RequestOptions.circleCropTransform()
                .placeholder(R.drawable.user_profile_icon_updated)
        )
        .into(object :
            CustomTarget<Bitmap>(UIHelper.dpToPx(this, 24), UIHelper.dpToPx(this, 24)) {
            override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                menuItem?.icon = BitmapDrawable(resources, resource)
              }

            override fun onLoadCleared(placeholder: Drawable?) {
            }
        })
question from:https://stackoverflow.com/questions/65943088/how-to-load-image-from-url-into-bottomnavigationview-menu-item-icon

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
500 views
Welcome To Ask or Share your Answers For Others

1 Answer

i recommended you to use chip navigation and create custom bottom navigation its very better than default android bottom navigation and more easy...

if you interest to learn you can use this tutorial https://www.youtube.com/watch?v=DQtdOSN21lQ&feature=emb_logo and the library https://github.com/ismaeldivita/chip-navigation-bar

if you have any question tag me to answer you


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...