(4.3.1.16)java.lang.NoSuchMethodException: setHomeActionContentDescription
来源:互联网 发布:淘宝买家敲诈食品卖家 编辑:程序博客网 时间:2024/06/05 17:37
当使用反射来获取方法 setHomeActionContentDescription
像这样:
Method setHomeActionContentDescription = ActionBar.class.getDeclaredMethod( "setHomeActionContentDescription", Integer.TYPE);
我得到 NoSuchMethodException:java.lang.NoSuchMethodException: setHomeActionContentDescription [int]
解决方法 1:
不幸的是,此方法不可用在 API 18 岁之前。即使使用反射,方法不是可用的。如果您想使用此方法,您可以从 SherlockNavigationDrawer 库使用一种变通方法:
try { setHomeAsUpIndicator = ActionBar.class.getDeclaredMethod("setHomeAsUpIndicator", Drawable.class); setHomeActionContentDescription = ActionBar.class.getDeclaredMethod( "setHomeActionContentDescription", Integer.TYPE); // If we got the method we won't need the stuff below. return; } catch (NoSuchMethodException e) { // Oh well. We'll use the other mechanism below instead. } final View home = activity.findViewById(android.R.id.home); if (home == null) { // Action bar doesn't have a known configuration, an OEM messed with things. return; } final ViewGroup parent = (ViewGroup) home.getParent(); final int childCount = parent.getChildCount(); if (childCount != 2) { // No idea which one will be the right one, an OEM messed with things. return; } final View first = parent.getChildAt(0); final View second = parent.getChildAt(1); final View up = first.getId() == android.R.id.home ? second : first; if (up instanceof ImageView) { // Jackpot! (Probably...) upIndicatorView = (ImageView) up; }
资料来源:https://github.com/nicolasjafelle/SherlockNavigationDrawer/blob/master/SherlockNavigationDrawer/src/com/sherlock/navigationdrawer/compat/SherlockActionBarDrawerToggleHoneycomb.java#L97
如你所看到的如果它是不可能来访问方法,他尝试直接得到 ImageView
。当你拥有它时,你可以直接做的 setContentDescription 或任何你想要的东西。
0 0
- (4.3.1.16)java.lang.NoSuchMethodException: setHomeActionContentDescription
- java.lang.NoSuchMethodException翻译
- java.lang.NoSuchMethodException 解决办法
- java.lang.NoSuchMethodException
- java.lang.NoSuchMethodException
- java.lang.NoSuchMethodException: 解决办法
- java.lang.NoSuchMethodException
- java.lang.NoSuchMethodException
- java.lang.NoSuchMethodException
- java.lang.NoSuchMethodException: $Proxy
- java.lang.NoSuchMethodException
- java.lang.NoSuchMethodException
- java.lang.NoSuchMethodException错误
- java.lang.NoSuchMethodException
- java.lang.NoSuchMethodException
- java.lang.NoSuchMethodException
- java.lang.NoSuchMethodException异常
- java.lang.NoSuchMethodException
- HightChart的HTML标签(labels)
- nao机器人远程及本地模块编写
- hdu 5442 长春区域赛网络赛 1006 Favorite Donut(后缀数组)
- 跑第一个hadoop自带示例遇到的错误
- 利用JDBC完成数据库的CRUD
- (4.3.1.16)java.lang.NoSuchMethodException: setHomeActionContentDescription
- 写给自己——卡方检测
- 5、支持向量机SVM
- http://write.blog.csdn.net/postedit
- android 开发环境下载地址
- 斯坦福Developing iOS 8 Apps学习笔记(六)
- 新一代 Linux 文件系统 btrfs 简介
- Connecting to the Controller(与控制器对象连接)
- 黑马程序员——C语言基础语法