Cannot get textAppearance to inherit/cascade from theme

by Walt Armour » Fri, 19 Feb 2010 14:25:00 GMT


Sponsored Links
 I have a simple style like this:

        <style parent="android:Theme.Light.NoTitleBar" name="MyTheme">
            <item name="android:colorBackground">#FFFFFF</item>
            <item name="android:textAppearance">@style/PrimaryText</
item>
        </style>

And a simple style like this:

    <style parent="@android:style/TextAppearance" name="PrimaryText">
        <item name="android:textColor">#FF0000</item>
        <item name="android:textSize">14sp</item>
    </style>

Now, I would expect (from reading everything that is documented) that
if I set the theme for my application like so:

    <application android:icon="@drawable/app_icon"
                                android:name=".MyApp"
                                android:theme="@style/MyTheme" >

then anything in my app that has a textAppearance attribute (like a
TextView) would inherit the attributes from MyTheme (and thus the
attributes from PrimaryText).

But they don't.  I tried setting the theme on the specific activity
(in the manifest) and that did not work.  I set the style attribute on
the containing layout like this:

    <LinearLayout
      android:id="@+id/myLayout"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_margin="5sp"
      style="@style/MyTheme"
      android:background="@drawable/round_border">

and that did nothing (which I believe is expected since this cascading
inheritance should only work when applied as a 'theme').

Am I missing something obvious here?  Right now I have to set the
textAppearance (or style) attribute on every single TextView to get
the style.  The pain is great.  Does anyone have a suggestion on a way
to get this to work?

While working this I also hit another oddity that may or may not be
related.  If I take the specific attributes (like textColor and
textSize) and put them in MyTheme then they do correctly cascade and
apply to all my text.  The problem is that they then cannot be
overridden by a style.  If I set textAppearance on a TextView it
appears to be ignored.  However, if I explicitly set textColor or
textSize then it will be honored and override the theme setting for
that TextView.

In general it feels like there is some missing wiring or a bit of
inconsistency in the application of themes and styling attributes.

--



Cannot get textAppearance to inherit/cascade from theme

by Prasanna Perera » Thu, 11 Mar 2010 02:06:24 GMT


 I am having this exact problem.  I am testing on the emulator.




--


Sponsored Links


Other Threads

1. dip and setting values in code

Hi

I have read about using a 'dip' scale rather than just px, this is
straightforward to implement in XML.
But how do I adjust values accordingly in the java code? For example:

tv.setTextSize(20)

will result in text of size 20 px right? What's the quickest way of
making this 20 dip, other than adding a resource?

Thanks

Kabir

--~--~---------~--~----~------------~-------~--~----~

2. How to hide user dictionary? or suggested words on keyboard

I haven't really looked into this, but I think that since this is a user
preference, it should be up to the user whether suggested words pop up or
not.










-- 
Andrew Burgess

--~--~---------~--~----~------------~-------~--~----~

3. How to hide user dictionary? or suggested words on keyboard

4. Getting Audio Metadata

5. Traffic filtering options

6. Disappearing Views with ListView

7. converting files to android