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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:40:36+00:00 2026-06-12T00:40:36+00:00

I’m trying to draw a rounded rect with a specific color, but i’m getting

  • 0

I’m trying to draw a rounded rect with a specific color, but i’m getting nothing.
I’ve already done lots of googling, and found some questions like this and read them all. However, none of them solved my problem. Why my onDraw method is never called?

Any help is appreciated.

public class RoundedTagItem extends RelativeLayout {

    Context ctx;
    String colorString;
    int color;

    public RoundedTagItem(Context context) {
        super(context);
        this.ctx = context;
        color = Color.WHITE;
        this.setWillNotDraw(false);
        this.setPadding(10, 0, 10, 0);
    }

    public RoundedTagItem(Context context, String color) {
        super(context);
        this.ctx = context;
        this.colorString = color;
        this.setWillNotDraw(false);
        this.setPadding(10, 0, 10, 0);
    }

    @Override
    protected void onDraw(Canvas canvas) {

       if(colorString != null)
             color = Color.parseColor("#" + colorString);

       int rectValue = 35;
       Log.d("Rounded", "rectValue: " + rectValue);
       RectF rect1 = new RectF(0, 0, rectValue, rectValue);

       Paint paint = new Paint();
       paint.setStrokeWidth(1);
       paint.setStrokeCap(Paint.Cap.ROUND);
       paint.setStyle(Paint.Style.FILL);
       paint.setAntiAlias(true);
       paint.setColor(color);

       canvas.save();
       canvas.drawRoundRect(rect1, 10, 10, paint);
       canvas.restore();

       super.onDraw(canvas);
    }

    public void ChangeBackgroundColor(String colorString) {
        color = Color.parseColor(colorString);
        invalidate();
    }

}

And then I put icons on this custom view on my main class:

// add category items to view
LinearLayout categories = (LinearLayout) findViewById(R.id.detailTagImagesLayout);
for(int i = 0; i < item.getCategoryItems().size(); i++) {

    RoundedTagItem v = null;
    if(i == 0) 
        v = new RoundedTagItem(DetailActivity.this, 
                           item.getCategoryItems().get(i).getColorCode());
    else 
        v = new RoundedTagItem(DetailActivity.this);            

    ImageView img = new ImageView(DetailActivity.this);
    img.setImageDrawable(Drawable.createFromPath(
                     item.getCategoryItems().get(i).getLightIconUrl()));
    v.addView(img);

    v.setTag(i);
    v.setOnClickListener(new TagClickListener());               

    categories.addView(v);
}
  • 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-12T00:40:37+00:00Added an answer on June 12, 2026 at 12:40 am

    Some improvements/problems you can make/fix…

    You can move these lines to your constructor:

    if(colorString != null)
       color = Color.parseColor("#" + colorString);
    

    Since this colorString never changes and the way you are doing it now you are calculating it every time onDraw is called (and he will be called a lot of times).

    Second please move your super.onDraw(canvas) to your first line.

    Third you need to define your LayoutParams on your constructor. If a View has 0 width/height its draw will never be called!

    this.setLayoutParams(new LayoutParams(150, 150));
    

    At last please make sure you are using your RoundTagItem. You can add this view to your xml using a tag like this: <your.package.RoundTagItem> where your.package is the package that you are using (com.something.blabla). If you use it like this please be sure you define the layout_width and the layout_height.

    You can also add your view programmatcly by adding to your root view (you get it by using findViewById(R.layout.your_root)) or by setting your view as the main content.

    RoundedTagItem myView = new RoundedTagItem(this);
    setContentView(myView);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to select an H1 element which is the second-child in its group

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.