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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:31:26+00:00 2026-06-03T20:31:26+00:00

I have colors in my String.xml file, as shown below: <?xml version=1.0 encoding=utf-8?> <resources>

  • 0

I have colors in my String.xml file, as shown below:

<?xml version="1.0" encoding="utf-8"?>
<resources>


      <string name="txtEmail">Email </string>
       <string name="txtPin">Pin Code</string>
       <string name="lblProtected"> Protected</string>

       <color name="MiscellaneousPercent">#ffff992b</color>
       <color name="MusicPercent">#ffffdd58</color>
       <color name="PicturesPercent">#ff48aa71</color>
       <color name="eBooksPercent">#ff00cff9</color>
       <color name="DocumentsPercent">#ff019df2</color>
</resources>

I want to use the these colors in class in my projects in order to iterate through the colors, by code.

    public class BreakDownBar extends View {

        public BreakDownBar(Context context, AttributeSet attrs) {
            super(context, attrs);
        }


            @Override
            protected void onDraw(Canvas canvas) {

                     for (int i = 0; i < 5; i++) {
            Paint paint = new Paint();
                        paint.setColor(/*I want to use the colors HERE*/); 
            }


                }
}

How can I use the colors in the onDraw method in SetColor()like above? Can I put the colors in the String.XMl file in an array?
Can any one help me?

  • 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-03T20:31:28+00:00Added an answer on June 3, 2026 at 8:31 pm

    You have to make use of your Context, and provide your resource in a array format and use it.

    public class BreakDownBar extends View {
    
        Context context=null;
    int res[]={R.color.black,R.color.blue,R.color.white,R.color.pink,R.color.grey};
    
            public BreakDownBar(Context context, AttributeSet attrs) {
                super(context, attrs);
                this.context=context;
            }
    
    
                @Override
                protected void onDraw(Canvas canvas) {
    
                         for (int i = 0; i < 5; i++) {
                           Paint paint = new Paint();
                           paint.setColor(res[i]));
                }
    
    
                    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something like the following (shown below) defined in my styles.xml file. But
I have color in the String.xml file like this <color name=ItemColor1>#ffff992b</color> how can i
I have the following XML <map version=1.0> <properties> <property name=color value=blue /> <property name=size
I have 4 string variables name, quest, favorite_color, speed that might be empty. I
How can I have different colors for different tabs in SuperTabNavigator. Below is the
I've been fighting this all day. Inside my styles.xml file I have color information
I have a string with XML: $string = <shoes> <shoe> <shouename>Shoue</shouename> </shoe> </shoes> ;
I have an XML file with property groups and properties. I want to retrieve
I have the following SyntaxDefinition.xml file that I am using to create syntax highlighting
I have extracted an XML file (using Export Test Suite functionality) in TestLink. The

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.