Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "android:textAppearance" on TextView/EditText fails, but "style" works

Tags:

android

This is a sample TextView in XML, which will properly apply the style TextContactContactName to the TextView.

<TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/photo"
        android:layout_alignTop="@id/photo"
        android:paddingLeft="10dp"
        android:text="First Last"
        style="@style/TextContactContactName"
        />

Now, I have some other things to set on this element, which are not text related. As such I tried to move the TextContactContactName and apply it via "android:textAppearance"

<TextView
    android:id="@+id/name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/photo"
    android:layout_alignTop="@id/photo"
    android:paddingLeft="10dp"
    android:text="First Last"
    android:textAppearance=@style/TextContactContactName"
    />

Unluckily, the text formatting is not being applied.

This is how the style (stored in res/values/styles-text.xml) looks like:

<style name="TextContactContactName">
    <item name="android:textSize">24sp</item>
    <item name="android:textColor">#333333</item>
    <item name="android:shadowColor">#ffffff</item>
    <item name="android:shadowDx">0</item>
    <item name="android:shadowDy">1</item>
    <item name="android:shadowRadius">1</item>
</style>

Am I using the textAppearance tag wrong?

I tested on Android 2.2 - HTC Desire.

like image 320
Sebastian Roth Avatar asked Mar 17 '11 10:03

Sebastian Roth


2 Answers

Ok, looks like my fault. I had made a quick test:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text styled using 'style'."
        style="@style/UiTestTextView"
        />
<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text styled using 'textAppearance'."
        android:textAppearance="@style/UiTestTextView"
        />

and the styles-text.xml:

<style name="UiTestTextView">
    <item name="android:textColor">#ff0000</item>
    <item name="android:textSize">16sp</item>

    <item name="android:shadowColor">#ffffff</item>
    <item name="android:shadowDx">1</item>
    <item name="android:shadowDy">2</item>
    <item name="android:shadowRadius">3</item>
</style>

The key thing is to remember that shadow* elements are not text properties. And as such will not be applied via textAppearance.

I'm going to ask on the Android Developers Mailing list if this is desired behavior.

like image 124
Sebastian Roth Avatar answered Sep 19 '22 19:09

Sebastian Roth


I filed a bug report on this issue. I think I got the standard reply "the shadow is not considered part of the text appearance".

http://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=35887

like image 43
slinden77 Avatar answered Sep 20 '22 19:09

slinden77