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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:15:23+00:00 2026-06-14T14:15:23+00:00

I want to have 2 selectable themes for my application. In order to do

  • 0

I want to have 2 selectable themes for my application. In order to do that, I defined some attributes, like this:

 <attr format="color" name="item_background" />

Then, I created both themes, like this:

  <style name="ThemeA">
     <item name="item_background">#123456</item>
 </style>

 <style name="ThemeB">
     <item name="item_background">#ABCDEF</item>
 </style>

This method works great, allowing me to create and modify several themes easily. The problem is that it seems that it can be used only in Views, and not in Drawables.

For example, referencing a value from a View inside a layout works:

 <TextView android:background="?item_background" />

But doing the same in a Drawable doesn’t:

 <shape android:shape="rectangle">
     <solid android:color="?item_background" />
 </shape>

I get this error when running the application:

    java.lang.UnsupportedOperationException: Can't convert to color: type=0x2

If instead of ?item_background I use a hardcoded color, it works, but that doesn’t allow me to use my themes. I also tried ?attr:item_background, but the same happens.

How could I do this? And why does it work in Views but not in Drawables? I can’t find this limitation anywhere in the documentation…

  • 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-14T14:15:24+00:00Added an answer on June 14, 2026 at 2:15 pm

    In my experience it is not possible to reference an attribute in an XML drawable.
    In order to make your theme you need to:

    • Create one XML drawable per theme.
    • Include the needed color into you drawable directly with the @color tag or #RGB format.

    Make an attribute for your drawable in attrs.xml.

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
       <!-- Attributes must be lowercase as we want to use them for drawables -->
       <attr name="my_drawable" format="reference" />
    </resources>
    

    Add your drawable to your theme.xml.

    <style name="MyTheme" parent="@android:style/Theme.NoTitleBar">
       <item name="my_drawable">@drawable/my_drawable</item>
    </style>
    

    Reference your drawable in your layout using your attribute.

    <TextView android:background="?my_drawable" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a application that like firefox, can be enhanced from plugins available from
I'm currently writing a filter for a selectable, I have some table cells that
i have a image that i don't want it drag-able or selectable so that
I want to have a UITableViewCell that is not selectable while its accessory view
I have seen this post: WPF ComboBox: background color when disabled and some others...
I have a group of FrameLayout which I want to be checkable/selectable, That is,
i have a GridView (selectable) in which I want to generate a dynamic GridView
I have some user controls which I want to specify properties and methods for.
I have a rich text box that I want to show as un-editable and
On my homepage I have a slideshow of pictures that are user selectable. I

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.