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)
Set The Text of The TextView You can set the text to be displayed in the TextView either when declaring it in your layout file, or by using its setText() method.
We use attribute android: hint= "Text will show here", so if we will set the TextView in the MainActivity.
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
You can apply a style read more here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With