8

How is it possible to set the Style of a TextView Child of a LinearLayout via style. Something like this:

<style name="MyLinearayoutStyle" parent="MyParentStyle">
    <item name="android:background">@drawable/mybackground</item>
    <item name="android:padding>5dp</item>
    // Here i need to define my textview style
</style>


<style name="MyTextViewStyle> parent="AnotherParentStyle">
    <item name="android:textColor">@color/Black</item>
    <item name="android:textSize">15sp</item>
</style>

I tried android:TextAppearance and android:textStyle, but this didnt work.

danijoo
  • 2,823
  • 4
  • 23
  • 43

2 Answers2

8

Change the theme definition ((stored in res/values/styles.xml):

<?xml version="1.0" encoding="utf-8"?> 
<resources>   
<style name="MyTheme" parent="android:Theme.Light">    
    <item name="android:textAppearance">@style/MyDefaultTextAppearance</item> 
</style>    
     <style name="MyDefaultTextAppearance" parent="@android:style/TextAppearance">    
     <item name="android:textSize">12sp</item>     
    <item name="android:textColor">#333</item>    
     <item name="android:textStyle">bold</item>   
    </style> 
    </resources>
anjaly
  • 518
  • 5
  • 12
  • 1
    This sets the same textappearance for every TextView in the Theme. I want to set the Appearance for only some childs. – danijoo May 17 '13 at 07:37
5

Inflate your TextView for example:

*textview.xml*

<?xml version="1.0" encoding="utf-8"?>
<TextView 
 style="@+style/MyLinearayoutStyle"
 />

and

activity.getLayoutInflater().inflate(R.layout.textview,(parent view), true);

Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
Oli
  • 3,496
  • 23
  • 32
  • Thats what im doing right now. Hoped there is a way i can set it for every childview without inflating every single view one by one. – danijoo May 17 '13 at 07:36
  • Oh okay sorry, than I dont know if theres a other solution ;) – Oli May 17 '13 at 07:43