Open stepango opened 10 years ago
I think the only problem with Action bar menu items is in the "com.android.internal.view.menu.ActionMenuItemView" class as toolbar works.
My solution is (bit on the ugly side)
in the CalligraphyFactory class add method
protected static boolean isActionMenuItemView(View view)
{
Class<?> aClass = null;
try
{
aClass = Class.forName("com.android.internal.view.menu.ActionMenuItemView");
}
catch (ClassNotFoundException e)
{
return false;
}
return view.getClass().equals(aClass);
}
and then use this like the work around for the action bar in onViewCreatedInternal method
final boolean deferred = matchesResourceIdName(view, ACTION_BAR_TITLE) || matchesResourceIdName(view, ACTION_BAR_SUBTITLE) || isActionMenuItemView(view);
Maybe you can improve on this solution and add it to your next release
Interesting I guess that could work. I'm not sure of the over head implications of that.
On Mon, 4 May 2015 11:04 dimskom notifications@github.com wrote:
I think the only problem with Action bar menu items is in the "com.android.internal.view.menu.ActionMenuItemView" class as toolbar works.
My solution is (bit on the ugly side)
in the CalligraphyFactory class add method
protected static boolean isActionMenuItemView(View view) { Class<?> aClass = null; try { aClass = Class.forName("com.android.internal.view.menu.ActionMenuItemView"); } catch (ClassNotFoundException e) { return false; }
return view.getClass().equals(aClass);
}
and then use this like the work around for the action bar in onViewCreatedInternal method
final boolean deferred = matchesResourceIdName(view, ACTION_BAR_TITLE) || matchesResourceIdName(view, ACTION_BAR_SUBTITLE) || isActionMenuItemView(view);
Maybe you can improve on this solution and add it to your next release
— Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/82#issuecomment-98660915 .
My solution worked nicely, maybe you can build on it for your next version. Great project !
@dimskom Glad that it works.
I guess, I would need to lazily init Class.forName()
as thats not exactly performant whilst iterating through inflating views.
here is more efficient and robust solution (sorry about the method, member names)
CalligraphyFactory.java
private static final String[] msSpecialClassesNames = new String[]{"com.android.internal.view.menu.ActionMenuItemView"};
private static HashMap<String, Class<?>> msSpecialClasses;
static
{
msSpecialClasses = new HashMap<>();
Class<?> aClass = null;
for (int i = 0; i < msSpecialClassesNames.length; i++)
{
try
{
aClass = Class.forName(msSpecialClassesNames[i]);
msSpecialClasses.put(msSpecialClassesNames[i], aClass);
}
catch (ClassNotFoundException e)
{
}
}
}
then add this method
protected static boolean shouldDeferView(View view)
{
return msSpecialClasses.containsKey(view.getClass());
}
then use it
final boolean deferred = matchesResourceIdName(view, ACTION_BAR_TITLE) || matchesResourceIdName(view, ACTION_BAR_SUBTITLE) || shouldDeferView(view);
Will this be supported in the near future?
@berendn if I can convince Google to inflate the views then that would be preferred. I don't want to be supporting loads of random hacks to do this.
MenuItems are added dynamically. We are looking at adding support for this. But might be during v2.0 rewrite where we need to traverse none inflated views.