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 6967927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:23:07+00:00 2026-05-27T16:23:07+00:00

I’m pretty sure that this question already has been answered somewhere. It just seems

  • 0

I’m pretty sure that this question already has been answered somewhere. It just seems too common. But I can’t find the answer. I can’t also figure out the solution.

Here’s the problem:

I want one of my TableRow’s to have different background color. It’s simple, I just need to add

android:background="#123456" 

In TableRow’s XML Declaration. But, I also want my application to have two themes. In the other theme, the TableRow should have different background color. I just can’t find a way to define a color value inside a theme and use it. I would like to type something like this:

<style name="Theme.MyApp" parent="@style/Theme.Light">
   <color "my_cool_color">#123456</color>
</style>

<style name="Theme.MyApp.Dark" parent="@style/Theme.Dark">
   <color "my_cool_color">#654321</color>
</style>

And, in TableRow’s declaration:

android:background="@color/my_cool_color"

So, when I change the theme, the color of that one TableRow’s background also changes. I’ve tried in many ways for many hours and didn’t succeed… One thing I didn’t try, was creating my own widget basing on TableRow and declaring a separate style for it – I think this should work, but it’s just too heavy solution for so simple problem.

  • 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-27T16:23:08+00:00Added an answer on May 27, 2026 at 4:23 pm

    You can do this using attributes. First define your attribute in attrs.xml (this file goes under the ‘values’ folder):

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <attr name="myCoolColor" format="color" />
    </resources>
    

    Then in your styles.xml, define myCoolColor for each theme:

    <style name="Theme.MyApp" parent="@style/Theme.Light">
       <item name="myCoolColor">#123456</item>
    </style>
    
    <style name="Theme.MyApp.Dark" parent="@style/Theme.Dark">
       <item name="myCoolColor">#654321</item>
    </style>
    

    Now, specify myCoolColor as the background of your view:

    android:background="?myCoolColor"
    

    You can go further and use a reference to a color so you can keep your colors defined in one place. Change the attribute to include a reference (note that we can use a color OR a reference):

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <attr name="myCoolColor" format="color|reference" />
    </resources>
    

    Change your styles.xml to reference a color for each theme:

    <style name="Theme.MyApp" parent="@style/Theme.Light">
       <item name="myCoolColor">@color/blue</item>
    </style>
    
    <style name="Theme.MyApp.Dark" parent="@style/Theme.Dark">
       <item name="myCoolColor">@color/green</item>
    </style>
    

    Finally define the colors in your colors.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="blue">#0000FF</color>
        <color name="green">#00FF00</color>
    </resources>
    

    That’s it!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.