Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling all TextViews(or custom view) without adding the style attribute to every TextView

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)

like image 504
Dominic Avatar asked Jul 23 '11 16:07

Dominic


People also ask

Which method is used to set the text in a TextView?

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.

Which attribute is used to show any text inside TextView?

We use attribute android: hint= "Text will show here", so if we will set the TextView in the MainActivity.


2 Answers

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

like image 163
vallllll Avatar answered Nov 15 '22 00:11

vallllll


You can apply a style read more here.

like image 45
HenrikS Avatar answered Nov 15 '22 00:11

HenrikS