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

nan*_*ani 6 android toolbar android-fragments

我需要一个有关的信息Toolbar.我想在Toolbar家里,新闻,搜索和消息中添加四张图片.所以我把它放入ImageviewToolbar.现在我不知道如何在这些图像中添加监听器......我怎么能这样做?我也有一个抽屉式导航栏,我想,如果你按ImageviewToolbar,你在一个新去Fragment的,而不是新的Activity.那我怎么能做这两件事呢?谢谢你的答案.

Ell*_*ltz 6

我猜你知道怎么把你的imageViews 添加到你的ToolBar如果不检查这个 ..之后得到你的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
Run Code Online (Sandbox Code Playgroud)