Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android apply style to custom TextView

I have a class, TextViewStyled, which extends TextView

In my theme XML, how do I apply a style to all my TextViewStyled widgets on Activities with a chosen theme?

I have this simple theme, but I want to limit the Black Gold style to TextViewStyled Widgets without specifying the Black Gold in the TextViewStyled style attribute. This is one of many themes which will be switched dynamically.:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyThemeOneofMany" parent="android:Theme.NoTitleBar.Fullscreen">
    <item name="android:???????????">@style/TextViewStyled_Black_Gold</item>
    </style>

    <style name="TextViewStyled_Black_Gold" parent="@android:style/Widget.TextView">            
          <item name="android:background">#1E1921</item>        
          <item name="android:textColor">#A85E4F</item>
          <item name="android:textColorLink">#FFBC4F</item>
          <item name="android:textStyle">normal</item>               
      </style>


</resources>
like image 931
Ian Vink Avatar asked Aug 10 '10 18:08

Ian Vink


1 Answers

For AppCompat theme (2.3.3+):

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="android:textViewStyle">@style/PizzaSizeWidget</item>
    </style>

    <style name="CustomTextView" parent="@android:style/TextAppearance.Widget.TextView">
        <item name="android:background">#1E1921</item>
        <item name="android:textColor">#A85E4F</item>
        <item name="android:textStyle">normal</item>
        <item name="android:textSize">93sp</item>
    </style>
like image 62
Gennadiy Ryabkin Avatar answered Sep 19 '22 14:09

Gennadiy Ryabkin