8

Is there a way to format all TextViews, Buttons or whatever with a theme ? Like in CSS when i want to format all a-tags

a{ /some css here/ }

I want to do that in android via xml when I'm applying a theme to my application. Any ideas ?Thanks

http://bartinger.at/

Update 1.0: I want to create a theme that formats the text in all TextViews green and in all EditTexts red. So that i just apply the theme and I never have to worry about the style attribute!

Update 1.1: So I found some that piece of code and I think that's a good beginning

<item name="android:textViewStyle">@style/MyTextView</item>
<item name="android:buttonStyle">@style/MyButton</item>

I think thats the answer to my question. But I have another one. I want to write my own ActionBar and wanted to know how I can apply a default style or default attributes (again without adding the style attribute in the layout xml :P )

I have a class

public class ActionBar extends LinearLayout{ }

and I'm gonna use it like that in my application

<at.bartinger.uil.ActionBar>....</at.bartinger.uil.ActionBar>

The ActionBar should have some default attributes (like height and width) and then adding some custom style attributes which could change from app to app (like background)

Dominic
  • 3,353
  • 36
  • 47
  • Sorry, no there is not a way to do this. – hackbod Jul 23 '11 at 17:07
  • i.e. where does the EditText gets it default height from ?? – Dominic Jul 25 '11 at 14:07
  • Thanks for this - your second update works a treat for me. I'm also looking to increase the size of text but I need it for all text, ie list items and edit text. Where did you find the info about textViewStyle? – Carrie Hall Apr 11 '13 at 13:18

3 Answers3

3

yes you can you can apply a theme to the whole application and then all your textviews will have that style.

Inside the styles.xml file you have to define your CustomTheme

for example:

<style name="CustomTheme" parent="android:Theme.Light">
  <item name="android:windowBackground">@color/custom_theme_color</item>
  <item name="android:colorBackground">@color/custom_theme_color</item>
</style>

you add something like text "android:textStyle="myStyle" and specify the details in Mystyle

jamesc
  • 12,423
  • 15
  • 74
  • 113
vallllll
  • 2,731
  • 6
  • 43
  • 77
2

You can apply a style read more here.

HenrikS
  • 4,170
  • 3
  • 34
  • 33
  • 1
    It was clear from the orignal question that the author already knows that you can apply a style to each element. The question was how to apply a theme to all elements that match a specific type without having to add style attributes to each element declaration in the XML layout files. -1 for not answering the question or even reading it. – Camsoft Feb 02 '12 at 12:22
  • @Camsoft The question was very different back when I answered it. The author has edited it multiple times after I answered it. – HenrikS Feb 04 '12 at 17:00
  • Maybe SO should not allow major edits to questions as changing the question after answers come in is just plain stupid. – Camsoft Feb 06 '12 at 11:48
0

for the action abr you should look here http://developer.android.com/guide/topics/ui/actionbar.html

especially at the bottom it explains very well how to style the bar

vallllll
  • 2,731
  • 6
  • 43
  • 77
  • No i mean on pre honeycomb devices. I'm writing an library to simplify the actionbar. and i know there already some libraries, but i decided to write my own. And its unnecessary if its the actionbar. The question is about how to add default attributes to an view that i created – Dominic Jul 25 '11 at 14:09