【发布时间】:2014-05-19 18:10:22
【问题描述】:
我正在使用以下方法在我的 Android ActionBar 上强制堆叠标签。
当我开始使用 proguard 时,类操作不再起作用。没有收到错误消息,我只是没有得到堆叠的选项卡 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) {}
}
【问题讨论】:
标签: java android reflection proguard