Prabs
Prabs

Reputation: 5163

How to refer to the style which contains text styling items

I've two themes,
AppTheme - for entire application and
AppTheme.NoActionBar - for navigation activity

In both the themes I've text styling.

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:fontFamily">sans-serif-light</item>
    <item name="android:textColor">@color/black_shade</item>
    <item name="android:textSize">@dimen/text_size</item>
    <item name="android:windowFullscreen">true</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:fontFamily">sans-serif-light</item>
    <item name="android:textColor">@color/black_shade</item>
    <item name="android:textSize">@dimen/text_size</item>
    <item name="android:windowFullscreen">true</item>
</style>

How do I group text-style-items and refer them in these two themes?

I've tried:

<style name="TextAppearance" >
    <item name="android:fontFamily">sans-serif-light</item>
    <item name="android:textColor">@color/black_shade</item>
    <item name="android:textSize">@dimen/text_size</item>
    <item name="android:windowFullscreen">true</item>
</style>  

And referred it by

    <item name="textAppearance">@style/TextAppearance</item>

It's not working.
How do I achieve this?

Upvotes: 0

Views: 86

Answers (2)

Gavin Harris
Gavin Harris

Reputation: 702

See: https://stackoverflow.com/a/3166865/5018798

My example (based on above):

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="android:textViewStyle">@style/TextAppearance</item>

    </style>

    <style name="AppTheme.NoActionBar" parent="AppTheme">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>

        <item name="android:textViewStyle">@style/TextAppearance</item>
    </style>

    <style name="TextAppearance" parent="android:Widget.TextView">
        <item name="android:textColor">#F00</item>
        <item name="android:textStyle">bold</item>
        <item name="android:textSize">55sp</item>
    </style>

</resources>

Upvotes: 2

tahsinRupam
tahsinRupam

Reputation: 6405

You can do the following:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
    ...
    <item name="android:textColorPrimary">Your color</item>
    ...
</style>

And set application theme in manifest to Apptheme:

<application
    ...
    android:theme="@style/AppTheme"
    .... 
    >

And you have to do this certainly otherwise text color won't change:

<style name="AppTheme.NoActionBar" parent = "AppTheme"> 

Upvotes: 0

Related Questions