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

  • Home
  • SEARCH
  • 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 9046759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:43:50+00:00 2026-06-16T11:43:50+00:00

I have a simple problem. I’d like to provide multiple themes for my UI

  • 0

I have a simple problem. I’d like to provide multiple themes for my UI that a user can switch between

The problem is that I can use a theme that styles primitive UI classes, or I can use a style directly on an XML layout element, but I can’t define a style that will then change based on the theme I have applied. Not all of the styling I want to do is based on the primitive type.

I would say that what I want to do is similar to using a CSS selector to style a class or ID, but themes only allow you to style an element name.


The best I can do right now is have a base style that inherits from EITHER of the actual styles I’ve built, as below:

My res/values/style.xml

// All styles have to be subclassed here to be made generic, and only one
// can be displayed at a time. Essentially, I'm doing the same thing as setting
// a theme does, but for styles. If I have 50 styles, I have to have 50 of
// these for each theme, and that's not DRY at all!
<style name="MyHeaderStyle" parent="MyHeaderStyle.Default"/>
<!--
    <style name="MyHeaderStyle" parent="MyHeaderStyle.Textures"/>
-->

<style name="MyHeaderStyle.Default">
    <item name="android:background">@android:color/background_dark</item>
</style>

<style name="MyHeaderStyle.Textures">
    <item name="android:background">@drawable/header_texture</item>
</style>

Usage in my layout.xml:

<!-- Note that I can't use a theme here, because I only want to style a
     SPECIFIC element -->
<LinearLayout android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              style="@style/MyHeaderStyle"
              android:gravity="center">
</LinearLayout>
  • 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-06-16T11:43:52+00:00Added an answer on June 16, 2026 at 11:43 am

    Try this method:

    1) Define your own res/values/attrs.xml file:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
        <declare-styleable name="AppTheme">
            <attr name="myLinearLayoutStyle" format="reference" />
        </declare-styleable>
    
    </resources>
    

    2) Assign the above attr to you LinearLayout

    <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  style="?attr/myLinearLayoutStyle"
                  android:gravity="center">
    </LinearLayout>
    

    3) Assign a concrete style to this attr:

    <style name="AppLightTheme" parent="android:Theme.Holo.Light">
        <item name="@attr/myLinearLayoutStyle">@style/lightBackground</item>
    </style>
    
    <style name="AppTheme" parent="android:Theme.Holo">
        <item name="@attr/myLinearLayoutStyle">@style/darkBackground</item>
    </style>
    
    <style name="lightBackground">
        <item name="android:background">#D1CBF5</item>
    </style>
    
    <style name="darkBackground">
        <item name="android:background">#351BE0</item>
    </style>
    

    Hope I understood correctly your question.

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

Sidebar

Related Questions

I have quite simple problem in SQL Server: User can have 12 items that
I have simple LINQ problem that I can't figure out. I have a table
i have a simple problem with that fetch_array. i like to read out x1
I have very simple problem that I can't solve. I need to do something
I have this simple problem that gets an input from the user using a
I have a simple problem that I have not been able to find an
I have a simple problem while putting text in multiple table! please have a
I have a simple problem that I've been stuck on for some time and
I have a simple problem that i cannot solve. I have a dictionary: aa
I have a simple problem but no matter what I try I can't see

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.