I understand that to apply a style you have to create the textview and apply the style programmatically, which I haven't figured out how to do yet, but what can you edit on the fly. Like text color? Background color? What things can or what cannot be edited on the fly from the java. Also can it be defined in the xml and then edited in the Java or must anything you want to change or set be defined solely from the Java?
The documentation for TextView lists the XML attributes that it supports, along with the method names for those that are supported at run time. Just about everything can be changed at run time, whether or not defined in XML (including every attribute you mentioned). The run-time changes override whatever is defined in XML.
Related
i am new in android development, i want to ask about the meaning of this snippet of xml code android:textAppearance="?android:attr/textAppearanceLarge". Does android framework will determine by itself the size of our text and choose large text relative to their choice?
I have tried to look up from this attribute declaration, but there is nothing that explain the property that will assign to text, and i also confuse by "?android" at the start of property.
My experience up until now when dealing with styles has been to create a style.xml file and create the properties I want for the style. If I want my style to be based on an existing style, I use the parent attribute. I then specify the style inside of my layout file on the controls that I want to apply the style to.
Where I am at a loss is when I want to use system styles and only update certain properties. I am wondering whether I can leave the layout files alone and not bother applying any styles to the controls. Instead, I would somehow update the property of the system style and that would update everywhere in my app where that style is already being used by default.
More specifically, I want to change the background color of the Actionbar but haven't found a way of doing it other than the way I described above.
You're probably looking for themes, which are collections of styles, applied either globally throughout the application, or for each Activity in particular. Start with this document and investigate further.
A style defined in XML resources cannot be "applied" at runtime.
So, given a style name, I would like to read the style items one by one, interpret them and apply them programmatically to selected widgets.
Because sometimes, a user may want to change the style of some widgets at runtime an I want that style to be exactly as the one defined in the resources.
The only reason I want to do it this way is to preserve consistency between the style defined in the XML resource and the style I appply at runtime.
How can I read the style items? I know one way: to parse the XML file myself, but maybe there are some built in methods to directly read the style I am not aware of.
Currently I'm mixing explicit attributes (layout_width, height, alignment) on my various XML layouts with coded styles in styles.xml, plus outsourcing colors from colors.xml.
From your experience, what's the recommended way to organize an android app's layouts?
Usings styles is way more organized and makes the xml code easier to read, I think that the visual editor for layouts sucks, so the best way to edit is still to manual edit text the file. Easier reading is a big plus.
I use style anywhere im repeating layouts, something that is very useful is that any explicits attributes will override those of the style, so you can use styles and if what you need is almost the same, you just explicitly redifine the attribute.
Any time you need to fix a layout issue you can update the style and not need to update it a million times.
On the other hand if you are just using that layout "style" once, there is no reason to write an actual style for it, just do it all explicitly.
I am following an example project "Sky" by Jeff Sharkey using styles in my layout. It is working out quite well, however, I cannot determine how to specify the font type-face using the styles. Without this, I will have to apply the font explicitly to every TextView, EditView, etc., whereas I want to control where and when it is applied throughout my application.
It seems that it is not possible from xml/styles... You can only specify it from java code.
check here if you are interesting.
You can do this by creating your own textview class and use that in your layouts.
Inside your new custom class, set the font you want.
Et voila!