How can I change my custom toolbar icon dynamically

前端 未结 2 1873
一个人的身影
一个人的身影 2021-01-29 09:57

In my application I\'m using toolbar which having imageview in it. I need to change that imageview dynamically .

Here is my toolbar.xm

2条回答
  •  忘掉有多难
    2021-01-29 10:47

    As per my comment Try this :

    final ImageView imageInToolbar = (ImageView) toolbar.findViewById(R.id.actionBarImage);
    setSupportActionBar(toolbar);
    imageInToolbar.setImageDrawable(ContextCompat.getDrawable(th‌​is, R.drawable.abc));
    

    For loading image from server :

    For Glide use :

    Glide.with(this)
         .load(url) 
         .into(imageInToolbar);
    

    In gradle : compile 'com.github.bumptech.glide:glide:3.8.0'

    For picasso use :

    Picasso.with(this).load(url).into(imageInToolbar);
    

提交回复
热议问题