Is toolbar's logo icon clickable?

后端 未结 3 1194
既然无缘
既然无缘 2020-12-19 06:27

i have used toolbar so now i want to apply click event over logo icon how can i get this event?

here is some coding stuff that i have done

Toolbar to         


        
3条回答
  •  鱼传尺愫
    2020-12-19 06:45

    I was asking myself the same question and came across this. I took a similar approach to Nikola Despotoski but with a different implementation.

    Instead of the method, what I did was:

    // Set drawable
    toolbar.setLogo(ContextCompat.getDrawable(context, R.drawable.logo));
    
    // Find logo
    View view = toolbar.getChildAt(1);
    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          // Perform actions
        }
      });
    

    Slightly hack-ish, but will come back review it a bit later. Sharing for discussion purposes.

提交回复
热议问题