Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Programmatically Change Style

I have over 50 XML Layouts/pages and need a way to determine a "base" font size for each screen type (small/medium/large). Actually, I need to specify other things, such as sizes for linear layouts.

In short, I want to differentiate sizes between small/medium/large devices.

1) Would I programmatically change the text size in styles.xml during launch?

This option is convenient because I wouldn't have to make 150+ XML Layouts.

2) Would I create three separate XML Layout's for the three sizes?

I would have to copy+paste each Style (*.small, *.med, *.large)... this sound like it will take a lot of work.

Any comments?

like image 719
Exegesis Avatar asked May 31 '26 08:05

Exegesis


1 Answers

I'm assuming that you know that you should use scalable units as stated in Vinay's answer:

http://developer.android.com/guide/practices/screens_support.html

I strongly recommend not to deviate from the "best practices" unless you really know what you're doing. It can only bring you problems down the road. I'm not a pro, that's why I try to follow the standards. OK, now let's answer:

When you want to use different sizes, and scalable units are not enough, you must declare them somewhere. So you are going to declare different files no matter what... it's inevitable. But then again, only when your scalable units are not enough to provide the desired visual effect across different screens.

To do that, you declare in value folders. Did you see the Google I/O app source on Google Code? It's "Google", and they do it very well. If you want to learn by example, that's probably the most complete resource I can think of. But it's a bit frightful at first.

It's so much to tell here (many simple questions... looks like you really don't know your way, sorry if it's not the case) that you are probably better off downloading that source tree.

Of course, both the values and layouts folders work in a transparent fashion (that's the whole point of using the standards), so you don't need to worry about screen variations across your layouts (when addressing key-values styles) and/or at runtime (when addressing both style and layout).

like image 66
davidcesarino Avatar answered Jun 01 '26 21:06

davidcesarino