特定于主题的 TextView 外观并不总是有效
我有这个相当奇怪的问题。我使用默认的 Android 外观来设置我的 TextView
的样式,除了一条接缝之外,所有接缝都可以完美地工作。
我使用的外观是 ?android:attr/textAppearanceSmall
,当我在布局 XML 设计器中并在 Holo
之间更改主题时,它会毫无问题地更改字体颜色代码> 和 Holo.Light
(Android 3.0+)。
但是,一个特定的 TextView
在平板电脑上运行时不会设置样式,并且它使用与其他正在运行的完全相同的 XML 代码。
这是我的 TextView
的 XML 代码,该代码不起作用:
<TextView android:id="@+id/textView1"
android:text="TextView"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_width="match_parent"
android:layout_marginTop="2sp"
android:lines="2"
android:gravity="top|center"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
我也尝试使用以下方法在代码中执行此操作,但这也不起作用:
setTextAppearance(this, android.R.attr.textAppearanceSmall);
有什么想法吗?
I've got this rather peculiar issue. I'm using the default Android appearances to style my TextView
s, and all but one seam to be working flawlessly.
The appearance I'm using is ?android:attr/textAppearanceSmall
, and it's changing the font color without any issues when I'm in the layout XML designer and change the theme between Holo
and Holo.Light
(Android 3.0+).
However, one particular TextView
won't be styled when it's running on the tablet, and it's using the exact same XML code as the others, that are working.
Here's my XML code for the TextView
that doesn't work:
<TextView android:id="@+id/textView1"
android:text="TextView"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_width="match_parent"
android:layout_marginTop="2sp"
android:lines="2"
android:gravity="top|center"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
I've also tried doing it in code using the following method, but that doesn't work either:
setTextAppearance(this, android.R.attr.textAppearanceSmall);
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我想指出,当使用相同样式(通过使用 XML)设计多个
View
组件时,有一种非常简洁的方式 为此创建样式。因此,您的样式可能如下所示:
而您的布局仅如下所示:
这使得代码更易于维护,并有助于防止拼写错误。
最后但并非最不重要的一点是,与您的问题类似的问题已经在此处进行了讨论。这也可能有助于解决您的问题。
First, I'd like to point out that when styling more then one
View
-component with the same style (by using XML), there is the very neat way of creating Styles for that.So your Style might look like this:
While your Layout only looks like this:
This makes the code much more maintainable and helps preventing typos.
Last but not least, something similar to your problem has already been discussed here. This might help solving your problem, too.