新的更新后,我发现操作栏和 LG 设备中可扩展/格式化字符串的兼容性问题。
这是我之前的代码:
SpannableString s = new SpannableString("About");
s.setSpan(new TypefaceSpan(this, "Sansation-Regular.ttf"), 0, s.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
getSupportActionBar().setTitle(s);
我相信 setTitle 崩溃时会出现以下错误:
java.lang.IllegalArgumentException: Invalid payload item type at android.util.EventLog.writeEvent(Native Method)
这会解决任何潜在的问题吗?我是 Android 新手,所以不知道。因为这个问题似乎只发生在使用 actionbarcompat 运行 4.1.2 的 LG 设备上 - 但因为我计划在未来添加对较低 API 级别的支持,所以我现在不想摆脱 actionbarcompat。
SpannableString s = new SpannableString("About");
s.setSpan(new TypefaceSpan(this, "Sansation-Regular.ttf"), 0, s.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
try{
getSupportActionBar().setTitle(s);
}catch(IllegalArgumentException e) {
getSupportActionBar().setTitle("About");
}
Thanks.!
PS:有问题的设备是 LG 运行的 4.1.2
显然这是Android本身的一个bug。它通过以下提交修复:
commit 332944f8a0a001c1754ce3298edbb4246e53c8fb
Author: zobject <[email protected] /cdn-cgi/l/email-protection>
Date: Mon Dec 10 22:52:59 2012 +0900
Fix EventLog string class problem in onOptionMenuSelected
EventLog function can handle string,integer class and long class. (in android_util_EventLog.cpp)
If menu title string are used bold tag(like <b>test</b>), it'll be android.text.SpannedString.
In onOptionMenuSelected, it is using item.getTitleCondensed() function for writing event log.
therefore any android activity using tag menu string(like <b></b>) can be crashed by IllegalArgumentException.
I found this crash on GMS Application.
change locale chinese -> launch Google+ -> hangout -> menu key -> Invite(expressed chinese) click -> Google+ crash
Change-Id: I0437be81699925e29bf4510eb615ef2424432763
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)