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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:43:38+00:00 2026-06-18T06:43:38+00:00

I am working on getting some meta-data working on Android. Most specifically, I am

  • 0

I am working on getting some meta-data working on Android. Most specifically, I am getting application-level meta-data to set a View’s background in the following formats:

<meta-data android:name="background"
           android:value="red" />

<meta-data android:name="background"
           android:resource="@drawable/my_red_background" />

<meta-data android:name="background"
           android:value="#FF0000" />

I am using the following code to parse the information:

ApplicationInfo app = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
Bundle metaData = app.metaData;
if (metaData != null) {
    int resourceID = metaData.getInt("background", -1);
    if (resourceID != -1) {
        //set the background resource of my view (THIS WORKS)
    }
    else {
        String background = metaData.getString("background");
        if (background != null) {
        try {
            backgroundColor = Color.parseColor(background);
            //Set background color (THIS WORKS for 'red', 'blue', etc.)
        }
        catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
    }

}

If I use the resource method and point it at a drawable, this works. If I use a color string like “red”, “blue”, “yellow”, etc – these also work. However, if I attempt to use a color in any of the formats preceded by a hashmark (#FF0000, #FFFF0000, etc), this does not work, even though the Android Documentation suggests that it should:

android:value description

Is this a known bug? Is there a simple workaround (other than just using a simple string or a drawable reference)? Or am I missing something? I am using a Asus Transformer Prime 10.1 TF301 Tablet to test (Android 4.0.3).

EDIT

I wanted to note that this is not a problem with Color.parseColor(). Android never enters the statement if (background != null), so somehow the meta data is not getting recognized as a String at all.

  • 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-18T06:43:39+00:00Added an answer on June 18, 2026 at 6:43 am

    Solved! This is not an Android bug, per-se, but rather an Android documentation bug (Surprise, surprise!). A hex color needs an escape character for it to be handled correctly:

    <meta-data android:name="background"
               android:value="\#FF0000" />
    

    enter image description here

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

Sidebar

Related Questions

I am having some problems getting a larger application with many table relationships working
So I'm working on getting some data with AJAX. All appears to work okay,
Background: I'm working on some code to read in data from a file. Examples
I am new to programing and I have some difficulties getting AlertDialog working. I
Hey all i am in need of some help getting my code working correctly
I am working on getting an autocomplete from a remote data source. It is
I'm working on getting rid of some warnings from a static code analysis. In
I'm working on getting some legacy code under unit tests and sometimes the only
I have been getting some massive head aches working on a very dynamic app.
I'm working on a large asp.net project and we're getting some exceptions, trouble is

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.