Does anyone know a way to get the drawable that is used for the ActionBarDrawerToggle after setting it in the constructor by resource ID? I am using a navigation drawer and I want to apply a color filter to the icon programmatically, but I can't figure out how to access it as a drawable. Any help would be appreciated. Thanks!
Asked
Active
Viewed 1,408 times
2
-
you mean the three strip image? – Rod_Algonquin Aug 12 '14 at 03:42
-
Yeah, that's the one. I can set it from a static resource drawable ID, but I want to be able to get the icon drawable to do a .setColorFilter on the image at runtime – frenziedherring Aug 12 '14 at 03:45
-
I don't think there's an easy way to do that, but if you look at my answer in the following link, it is represented by `upView` in the `shiftHomeView()` method: http://stackoverflow.com/questions/24240439/samsung-galaxy-s4-misaligns-the-actionbar-icon/24980936#24980936 – Mike M. Aug 12 '14 at 08:13
-
@MikeM. That works, but is so hacky. I can't find another way though. Post it as an answer and I'll accept it (unless a better solution shows up). Thanks! – frenziedherring Aug 12 '14 at 13:43
-
Actually, IIRC, you might not have to "go that far out" in the hierarchy, but it'll still be hacky. Lemme check. – Mike M. Aug 12 '14 at 13:56
-
I'm doing a findViewById(android.R.id.home).getParent().getChildAt(0) which appears to be working well – frenziedherring Aug 12 '14 at 14:07
1 Answers
2
As the framework's ID for that View is hidden, the only way I've found to access it is by walking through the hierarchy based on the Home View's position in it.
public ImageView getUpView()
{
ViewGroup parentView = (ViewGroup) findViewById(android.R.id.home).getParent();
return (ImageView) parentView.getChildAt(0);
}

Mike M.
- 38,532
- 8
- 99
- 95
-
1This approach won't work if you're using an ActionBarDrawerToggle from support.v7. See [my answer here](http://stackoverflow.com/a/33554037/770068) for a method that works with support library 23.1. – Lorne Laliberte Nov 05 '15 at 20:26
-
Or [my answer here](http://stackoverflow.com/questions/28279953/get-reference-to-drawer-toggle-in-support-actionbar/28280347#28280347). – Mike M. Nov 12 '15 at 04:45