android - 可以在工具栏中添加 imageview 吗?

标签 android android-fragments toolbar

我需要有关工具栏 的信息。我想在我的 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/

相关文章:

css - ckeditor 工具栏图标和按钮错位

java - 如何在没有应用程序小部件 Activity 的情况下注册广播接收器?

android - 按下回车键时如何使键盘消失

android - fragment 管理器上的空指针异常

android - 如何在两个 fragment 之间传递数据?

css - JCE 编辑器工具栏图标未正确加载

delphi - 在运行时更改工具按钮的图片不再起作用

android - 在维度中分配包装内容

android - "Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++."启动后台服务并关闭应用后

android - 从 Fragment 调用 FragmentActivity