1

I'm experiencing a strange behaviour with textviews hosted into a TableRow: it looks like as they are rendered using the a smaller font than the rest of the app.

I KNOW that it's better to use an XML and inflate it, so it's what I'm going to do next, but now I am just curious to understand what's happening...

I have an XML with a TableLayout. Inside there is a TableRow. Inside the TableRow, a TextView. I have defined a style to have all the TextView in my app using the textAppearanceMedium style. It works. Now, I add new TableRow (each one with its own TextView) programmatically: what happens is that all the TextView in the new rows are using a smaller font then the first one. And even if I explicitly set the textAppearanceMedium, nothing happens.

It must be something obvious. What I'm missing?

Thx all in advance.

Mifeet
  • 12,949
  • 5
  • 60
  • 108
Mauro
  • 11
  • 2

1 Answers1

0

You can't set a style programmatically. My guess is your style is not applying when you are creating everything in code.

Read this here: android set style in code

The fix is, as you hinted at, to set the style in XML and inflate the objects from XML programmatically and then add them as needed.

Community
  • 1
  • 1
Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
  • This sound reasonable so no problem with it. Still, I cannot understand why the newly created TextView do not inherits the app theme. – Mauro Jun 04 '13 at 15:06
  • Just make it in XML and it will work. I didn't write Android, I just code in it :) – Ken Wolf Jun 04 '13 at 15:09
  • Lol. I understand your pov, but I really hate to not know why things happens :-D – Mauro Jun 04 '13 at 21:45
  • This is from the Android development team: (https://groups.google.com/forum/#!msg/android-developers/P6vfKr5tqlY/X6204pvErjIJ) but they don't really explain it. – Ken Wolf Jun 05 '13 at 02:03