可以在工具栏中添加imageview吗? [英] It's possible to add imageview in a toolbar?

查看:58
本文介绍了可以在工具栏中添加imageview吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关工具栏的信息.我想在我的 Toolbar 中添加四张图片,例如首页,新闻,搜索和消息.因此,我将 Imageview s放在了 Toolbar 中.现在我不知道如何在这些图像上添加侦听器...我该怎么做?我也有一个导航抽屉,我想要,如果您按 Toolbar 中的 Imageview ,您会进入一个新的 Fragment ,而不是新的 Activity .那我该怎么做这两件事呢?谢谢您的回答.

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 Imageviews 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.

推荐答案

我想你知道如何将 imageView 添加到 ToolBar 中,如果未选中.您的 ToolBar 使用 findViewById

i guess you know how to add your imageViews 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

这篇关于可以在工具栏中添加imageview吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆