好的,我正在使用API 15-20的Android Studio 0.8.14
我有一个TextView tvInitials
,我已初始化,并将其设置为
tvInitials = new TextView(context);
tvInitials.setLayoutParams(params);
tvInitials.setGravity(Gravity.CENTER);
tvInitials.setBackgroundResource(R.drawable.post_avatar_bg);
tvInitials.setTextAppearance(context, R.style.someStyle); //<Problematic line
<style name="someStyle">
<item name="android:background">#FFFF0000</item>
<item name="android:textSize">21sp</item>
</style>
但我在android studio中的布局查看器给了我这个:
android.content.res.Resources$NotFoundException
at com.android.layoutlib.bridge.android.BridgeContext.obtainStyledAttributes(BridgeContext.java:484)
at android.widget.TextView.setTextAppearance(TextView.java:2484)
at com.vvminovv.bugtest.view.AvatarView.init(AvatarView.java:57)
at com.vvminovv.bugtest.view.AvatarView.<init>(AvatarView.java:35)
____MORE WHERE THIS CAME FROM, ASK FOR IT IF IT HELPS____
但是,如果我在手机上运行应用程序,它似乎完全正常。问题仅出现在Design
和Text
标签中的布局查看器中。
如果我删除有问题的行:
tvInitials.setTextAppearance(context, R.style.someStyle);
布局不再给我错误(但显然也没有给它设置样式)
只是为了做一个完整性检查,我检查了样式是否有问题,所以我将它添加到我的布局中的一个textViews中:
<TextView
android:id="@+id/tvTitle"
style="@style/someStyle"/>
这完美无缺。所以我在动态应用这种风格时遇到了麻烦。
我还发现,如果我尝试在AvatarView.java
中的构造函数中执行此操作:
tvInitials = new TextView(context, null, R.style.someStyle); //<Changed the constructor
tvInitials.setLayoutParams(params);
tvInitials.setGravity(Gravity.CENTER);
tvInitials.setBackgroundResource(R.drawable.post_avatar_bg);
//tvInitials.setTextAppearance(context, R.style.someStyle); //<Problematic line
布局查看器提供了不同的错误:
Failed to find style 'someStyle' in current theme
,它也无法在Android上正确呈现,因此我们已将其删除作为选项。
感谢您的帮助。
答案 0 :(得分:0)
与开发团队核实,他们将其标记为界面中的错误。
检查信息here
答案 1 :(得分:0)
面对类似问题并通过从xml布局文件中删除textAppearance语句解决,这个bug也在2.3.3版本中