Search code examples
androidstylestextviewthemes

Setting Style of underlying TextViews in style.xml


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.


Solution

  • 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);