I would like to highlight drawer icon in my Toolbar
(working on a tutorial). For that, I need its position. How do I get a reference to drawer's navigation icon (hamburger) view?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Improvised @Nikola Despotoski's answer
If you just want to get the
Drawable
representing the toolbar navigation icon, you can do this:You can get a reference to the ImageButton used for the toolbar's navigation icon by having a method as this:
After looking into Toolbar's child views in debug mode, I saw that drawer icon can be found there, as an ImageButton. (Thanks Elltz)
I use a Toolbar with custom xml layout with 2 children (LinearLayout and ImageView), so my Toolbar had 4 children in the end, with these positions:
Knowing this, I can now use:
to get a reference to drawer menu icon. In my case, the position is 2. This position should be equal to the number of child view's in your custom toolbar layout.
If someone finds better solution please let me know.
You can make use of content description of the view and then use
findViewWithText()
method to get view referenceMore