安卓 java。lang.NoSuchMethodException:setHomeActionContentDescription[int]?
当我使用反射获取方法setHomeActionContentDescription
时,如下所示:
Method setHomeActionContentDescription = ActionBar.class.getDeclaredMethod(
"setHomeActionContentDescription", Integer.TYPE);
我没有得到任何异常:
java.lang.NoSuchMethodException: setHomeActionContentDescription [int]
# 1 楼答案
不幸的是,这种方法在API 18之前不可用。即使使用反射,该方法也不可用。如果要使用此方法,可以使用SherlockNavigationDrawer库中的解决方法:
资料来源:https://github.com/nicolasjafelle/SherlockNavigationDrawer/blob/master/SherlockNavigationDrawer/src/com/sherlock/navigationdrawer/compat/SherlockActionBarDrawerToggleHoneycomb.java#L97
如您所见,如果无法访问方法,他会尝试直接获取ImageView。当你有了它,你可以直接做一个setContentDescription或者任何你想做的事情