Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7027997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:19:39+00:00 2026-05-28T00:19:39+00:00

I am using custom attributes to implement theme switching in my application. I have

  • 0

I am using custom attributes to implement theme switching in my application. I have the following attribute defined:

<resources>
    <attr name="TextAppearance_Footer" format="reference"></attr>
</resources>

I have two themes which define this attribute differently:

<style name="NI_AppTheme.Dark">
    <item name="TextAppearance_Footer">@style/Footer</item>
</style>

The @style/Footer is defined as follows:

<style name="Footer" parent="@android:style/TextAppearance.Large">
    <item name="android:textColor">#00FF00</item> // Green
</style>

Now if I try to set this style to a TextView using:

textView.setTextAppearance(this, R.attr.TextAppearance_Footer);

It does not work (i.e. does not set the text to Green). However, if I specify the text appearance via xml using:

android:textAppearance="?TextAppearance_Footer"

It works fine. What could I be missing? I need to set the attributes because I want to dynamically be able to switch between themes.

Additional Info:

If I use:

textView.setTextAppearance(this, R.style.NI_AppTheme.Dark);

It seems to work all right.

EDIT: Tested Working Solution (thanks @nininho):

Resources.Theme theme = getTheme();
TypedValue styleID = new TypedValue();
if (theme.resolveAttribute(R.attr.Channel_Title_Style, styleID, true)) {
     channelTitle.setTextAppearance(this, styleID.data);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:19:40+00:00Added an answer on May 28, 2026 at 12:19 am

    Why not use:

    textView.setTextAppearance(this, R.style.Footer);
    

    I think that the textAppearance must be a style.

    Edit:

    Maybe you should try this:

    TypedArray a = context.obtainStyledAttributes(attrs,
    new int[] { R.attr.TextAppearance_Footer });
    
    int id = a.getResourceId(R.attr.TextAppearance_Footer, defValue);
    textView.setTextAppearance(this, id);
    

    EDIT:
    Correct Tested Code:

    Resources.Theme theme = getTheme();
    TypedValue styleID = new TypedValue();
    if (theme.resolveAttribute(R.attr.Channel_Title_Style, styleID, true)) {
         channelTitle.setTextAppearance(this, styleID.data);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started using custom intents in my application and I have come across
Recently I have been reading more and more about people using custom attributes in
When using HTML custom attributes it doesn't works in Chrome. What I mean is,
I have been using custom swc based components for my new flash game. I
I am trying to implement Custom Error handling via Action Filter Attributes. My code
I'm trying to implement my custom security attribute. It's very simple for now [Serializable]
Inside my XAML I have two custom components: <gui:CustomerBrowser x:Name=browser CustomerDetailView=??? VerticalAlignment=Stretch HorizontalAlignment=Stretch />
I'm using custom attributes in my game to allow me to define dependencies between
How do you give a C# Auto-Property a default value, using a custom attribute?
I have a custom XML schema defined for page display that puts elements on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.