我正在使用以下方法在我的Android ActionBar上强制堆叠选项卡。
当我开始使用proguard时,Class操作不再工作。没有收到错误信息,我只是没有得到堆叠标签ActionBar。
这是我在proguard规则中的内容。有什么我遗漏的吗?
-keepattributes Signature
-keepattributes *Annotation*
-keep class java.lang.reflect.** { *; }
-keep class com.company.myapplication1.SetStackedTabs.** { *; }
_
public static void SetStackedTabs(Object inActionBar, final boolean inHasEmbeddedTabs){
// get the ActionBar class
Class<?> actionBarClass = inActionBar.getClass();
// if it is a Jelly Bean implementation (ActionBarImplJB), get the super class (ActionBarImplICS)
if ("android.support.v7.app.ActionBarImplJB".equals(actionBarClass.getName()))
{
actionBarClass = actionBarClass.getSuperclass();
}
// if Android 4.3 >
if ("android.support.v7.app.ActionBarImplJBMR2".equals(actionBarClass.getName())){
actionBarClass = actionBarClass.getSuperclass().getSuperclass();
}
try
{
// try to get the mActionBar field, because the current ActionBar is probably just a wrapper Class
// if this fails, no worries, this will be an instance of the native ActionBar class or from the ActionBarImplBase class
final Field actionBarField = actionBarClass.getDeclaredField("mActionBar");
actionBarField.setAccessible(true);
inActionBar = actionBarField.get(inActionBar);
actionBarClass = inActionBar.getClass();
}
catch (IllegalAccessException e) {}
catch (IllegalArgumentException e) {}
catch (NoSuchFieldException e) {}
try
{
// now call the method setHasEmbeddedTabs, this will put the tabs inside the ActionBar
// if this fails, you're on you own <img class="wp-smiley" alt=";-)" src="http://www.blogc.at/wp-includes/images/smilies/icon_wink.gif">
final Method method = actionBarClass.getDeclaredMethod("setHasEmbeddedTabs", new Class[] { Boolean.TYPE });
method.setAccessible(true);
method.invoke(inActionBar, new Object[]{ inHasEmbeddedTabs });
}
catch (NoSuchMethodException e) {}
catch (InvocationTargetException e) {}
catch (IllegalAccessException e) {}
catch (IllegalArgumentException e) {}
}
已解决
我必须在ProGuard配置中输入这一行。
-keep class android.support.v7.** { *; }