Aby biblioteka kompatybilności działała i uniknęła "java.lang.illegalstateexception: fabryka została już ustawiona na tym layoucie", musisz uzyskać ostateczne odwołanie do już ustawionej Fabryki i wywołać jej naCreateView w swojej własnej Fabryce. onCreateView. Przed że introspekcja trik musi być użyty, aby umożliwić Ci ustawić jeszcze raz fabrykę do LayoutInflater:
LayoutInflater layoutInflater = getLayoutInflater();
final Factory existingFactory = layoutInflater.getFactory();
// use introspection to allow a new Factory to be set
try {
Field field = LayoutInflater.class.getDeclaredField("mFactorySet");
field.setAccessible(true);
field.setBoolean(layoutInflater, false);
getLayoutInflater().setFactory(new Factory() {
@Override
public View onCreateView(String name, final Context context, AttributeSet attrs) {
View view = null;
// if a factory was already set, we use the returned view
if (existingFactory != null) {
view = existingFactory.onCreateView(name, context, attrs);
}
// do whatever you want with the null or non-null view
// such as expanding 'IconMenuItemView' and changing its style
// or anything else...
// and return the view
return view;
}
});
} catch (NoSuchFieldException e) {
// ...
} catch (IllegalArgumentException e) {
// ...
} catch (IllegalAccessException e) {
// ...
}
nie działa. Rzucanie "android.view.InflateException: Binarna linia pliku XML nr 17: Błąd podczas nadawania klasy com.android.internal.view.menu.ActionMenuItemView" – MSIslam
właściwie nie jest już zgłaszanego wyjątku, ale mój kolor tekstu jest nadal szary: ( –