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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:14:16+00:00 2026-05-30T10:14:16+00:00

I am currently setting up 3 textviews that go into a LinearLayout(code below). However

  • 0

I am currently setting up 3 textviews that go into a LinearLayout(code below). However the last color that is assigned using the setColor method only seems to apply to the first textview and in fact overwrites the color that i had initially set for it.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);

    TextView view1 = new TextView(this);
    view1.setText("I am view one");
    view1.setTextColor(ColorStateList.valueOf(Color.RED));
    view1.setTextSize(25);
    view1.setGravity(Gravity.CENTER);

    TextView view2 = new TextView(this);
    view2.setText("I am view two");
    view1.setTextColor(ColorStateList.valueOf(Color.BLUE));
    view2.setTextSize(30);
    view2.setGravity(Gravity.CENTER);

    TextView view3 = new TextView(this);
    view3.setText("I am view three");
    view1.setTextColor(ColorStateList.valueOf(Color.YELLOW));
    view3.setTextSize(50);
    view3.setGravity(Gravity.CENTER);


    LinearLayout myLinearLayout = new LinearLayout(this);
    myLinearLayout.setOrientation(LinearLayout.VERTICAL);
    myLinearLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    myLinearLayout.setGravity(Gravity.CENTER);
    myLinearLayout.addView(view1);
    myLinearLayout.addView(view2);
    myLinearLayout.addView(view3);

    setContentView(myLinearLayout);

In this case view1 is yellow and the other views are grey…red and blue aren’t being applied to the correct views. As a note i initially had just tried to use setColor and as you can see i was trying to use ColorStateList per the documentation but the same results apply. Anyhow, how would i go about forcing the color i want on the different textviews? I know this should be easy, perhaps i am just missing something here. thanks all in advance.

  • 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-05-30T10:14:17+00:00Added an answer on May 30, 2026 at 10:14 am

    Note the objects you are setting the colors on – it seems like there’s a whole bunch of copy-paste left-overs. Every color assignment is done on view1, whereas what you really want is to set the color in the second assignment to view2, and in the third to view3:

    TextView view1 = new TextView(this);
    view1.setText("I am view one");
    view1.setTextColor(ColorStateList.valueOf(Color.RED));
    view1.setTextSize(25);
    view1.setGravity(Gravity.CENTER);
    
    TextView view2 = new TextView(this);
    view2.setText("I am view two");
    view2.setTextColor(ColorStateList.valueOf(Color.BLUE)); // <-- view2
    view2.setTextSize(30); 
    view2.setGravity(Gravity.CENTER);
    
    TextView view3 = new TextView(this);
    view3.setText("I am view three");
    view3.setTextColor(ColorStateList.valueOf(Color.YELLOW)); // <-- view3
    view3.setTextSize(50);
    view3.setGravity(Gravity.CENTER);
    

    By the way, simple calling .setColor(Color.RED) (or a different color) on the views should suffice.

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

Sidebar

Related Questions

I am currently setting up a master-slave app using Ruby on Rails that needs
I'm currently setting up a new project, and I have run into a few
I'm currently setting individual pixels on the canvas within a loop using the fillRect
I am using ASP.NET Forms Authentication and currently setting the timeout value in Web.config.
Currently setting up a backup solution that sends a database dump and some other
I currently setting margin like below successfully: $('div#container_join_messages').css({'margin-right': '56.5%'}); $('div#container_join_errors').css({'margin-right': '56.5%'}); $('div#container_join_now').css({'margin-right': '56.5%'}); Is
I'm currently setting up replication in order to produce a database that will be
I'm currently setting up a new production environment for a Rails application which includes
I'm currently setting up CI for my project and have team city configure and
I am currently setting the connection string for my linq to sql data context

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.