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 c开发者_StackOverflowode 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?
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:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- The Style for all the TextViews -->
<style name="TextViewStyle">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_alignParentBottom">true</item>
<item name="android:layout_alignParentLeft">true</item>
<item name="android:layout_width=">match_parent</item>
<item name="android:layout_marginTop">2sp</item>
<item name="android:lines">2</item>
<item name="android:gravity">top|center</item>
<item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
</style>
</resources>
While your Layout only looks like this:
<TextView android:id="@+id/textView1"
android:text="TextView"
style="@style/TextViewStyle"
/>
<TextView android:id="@+id/textView2"
android:text="Another TextView"
style="@style/TextViewStyle"
/>
<!-- .... -->
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.
精彩评论