I need an information about Toolbar
. I would like to add four images in my Toolbar
like home, news, search and message. So i've putting Imageview
s in the Toolbar
. Now I don't know how to add listener at these images...how could I do that?
I have also a navigation drawer and I want that, if you press the Imageview
in the Toolbar
, you go in a new Fragment
and not in a new Activity
.
So how could I do these two things?
Thank you for the answers.
i guess you know how to add your imageView
s to your ToolBar
if not check this .. After that get a reference to your ToolBar
use findViewById
Toolbar tool = finViewById(R.id.mytoolbar);//cast it to ToolBar
ImageView im1 = tool.findViewById(R.id.myimageviewone); // cast it
//same for the others
// now you can set your click listeners
//in your onclick listeners you use fragmentmanager along with fragmenttransaction
//to start a new fragment in your layout or on your layout, you can google
// for that
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With