0

is there a way to define a style that affects all Views in an Activity of a given type, without editing all of the xml View tags to define the style. is there a way to define something like "all TextViews in this Activity have a minHeight of 70sp"?

Charles
  • 50,943
  • 13
  • 104
  • 142
moonlightcheese
  • 10,664
  • 9
  • 49
  • 75
  • Something like a custom theme(only for that particular activity) for which you set the desired views attributes? – user Aug 28 '12 at 06:52
  • well, yes, i think. but i want to style/theme only Views of a specific type. i'm trying to avoid explicitly defining the style for each TextView instance, as it just seems like there ought to be a way to do this. and if there isn't, there should be. – moonlightcheese Aug 28 '12 at 06:59
  • See http://stackoverflow.com/questions/10903647/set-a-consistent-style-to-all-edittext-for-e-g. Worked for me. – Code Poet Aug 28 '12 at 07:19

2 Answers2

1

A theme is what you want. Each android widget has a default style that you could override to make it as you want. For example:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="TextViewSpecial" parent="@android:style/Theme">
        <item name="android:textViewStyle">@style/SpecialTextView</item>
    </style>
</resources>

a theme that overrides the style for a TextView. SpecialTextView is a style like this:

<style name="SpecialTextView" parent="@android:style/Widget.TextView">
    <item name="android:minHeight">70sp</item> <!-- use dp instead of sp --       
</style>

Then simply set the TextViewSpecial theme in the manifest to the desired activity. You can use this method to ovreride the style of what widget you want.

user
  • 86,916
  • 18
  • 197
  • 190
0

Just define a theme for the layout.

Teodor
  • 300
  • 1
  • 13