我需要有关工具栏
的信息。我想在我的 Toolbar
中添加四个图像,例如主页、新闻、搜索和消息。所以我将 Imageview
放在了 Toolbar
中。现在我不知道如何在这些图像上添加监听器……我该怎么做?
我还有一个抽屉导航,我想要它,如果你在 Toolbar
中按下 Imageview
,你会进入一个新的 Fragment
而不是一个新的 Activity
。
那我怎么能做这两件事呢?
感谢您的回答。
最佳答案
我猜你知道如何将你的 imageView
添加到你的 ToolBar
如果不检查 this .. 之后获取对您的 ToolBar
的引用,使用 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
关于android - 可以在工具栏中添加 imageview 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30276281/