How can I change my custom toolbar icon dynamically

前端 未结 2 1825
一个人的身影
一个人的身影 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:25

    Try this

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
    
    toolbar.setNavigationIcon(getResources().getDrawable(R.drawable.back_arrow));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    
    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题