2

Let's say i have a layout with style:

<LinearLAyout ... >
    <TextView ... style=someStyle />
    <ImageView ... style=someImageStyle ... />
</LinearLayout>

the style will be defined in an xml in my project. How can i override that style with an external xml ? (i'm asking because i've noticed the View does not have applyStyle\setStyle or anything of that sort (best bet, because style need to be parsed, compared against android:attr for validation and then applied on each item of the view). I do wonder how am i suppose to make downlaodable themes for my app.

codeScriber
  • 4,582
  • 7
  • 38
  • 62
  • i did read android's 'apply styles and themes' already this issue is not mentioned there :-) – codeScriber Oct 18 '10 at 09:02
  • did you by chance read this http://stackoverflow.com/questions/2016249/how-to-programmatically-setting-style-attribute-in-a-view – Terrance Dec 08 '10 at 17:20
  • yup, it's unfortunately what i though... i think it's a bit lame i can't have a loader like for dimensions and colors for example one for style that creates attribute object i can pass on to the C'tor of an object OR use in applyStyle() it would be the same as defining ever.ything in xml files and then programatically setting them – codeScriber Jul 20 '11 at 14:56

1 Answers1

1

After some experience i can share my thoughts about it here in my own question... So first remark is, even in your own styles, use Dimentions and colors and attributes as much as you can. this way if you ever want to programatically apply a style to a view you can use getResources.getDimen... , getRessources().getColor(), getResrouces.getDrawable() etc...

In addition you can take the code from the aapt or open an existing apk and take the compiled xml from there and then use the same code reading the xml (it's C code mind you!!!) from android source. i would not do it from the simple reason it's an overkill to apply a simple style to a view. The time it takes to write the method is too short. and if you must do it in xml, you can create an xml file with just your view and then inflate it, you can't replace the style in run time though. for that you have to define your own mechanism to replace colors, sizes, backgrounds etc... and supply the images as well, which is not so easy, reading those images from the local storage, if i'm not mistaken is less productive then readin them from assets or drawable directories.

codeScriber
  • 4,582
  • 7
  • 38
  • 62