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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:51:19+00:00 2026-05-25T16:51:19+00:00

I have an activity with a layout and some buttons in it, I want

  • 0

I have an activity with a layout and some buttons in it, I want to change color of those buttons. But there are lot more buttons so I want to change them using a method defined in other class. Is this possible? I tried by creating a new class which extends the current class. But it is getting force closed.

public class Color_change extends Calculate
{
    public  void test()
    {
        Button button = (Button)findViewById(R.id.one);
        button.setTextColor(0xFFFF0000);
    }
}

Calculate is a main class which extends Activity. And I’m calling as below:

Color_change a = new Color_change();
a.test();
  • 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-25T16:51:20+00:00Added an answer on May 25, 2026 at 4:51 pm

    If the current Activity being displayed on the screen isn’t Color_change the code you wrote will not function. If you want to have a separate class that changes the color of a set of buttons, I would suggest passing the buttons in some form of collection to the class that changes the button color. You could write a class like this:

    public class ColorChanger
    {
      public void changeColor(Collection<Button> buttons)
      {
        for(Button b : buttons) {
           changeButtonColor(b);
        }
      }
    
      private void changeButtonColor(Button button) {
           switch(button.getId()) {
               case R.id.one:
                    button.setTextColor(0xFFFF0000); 
                    break;
               default: 
                    // set default color?
                    break;
           }
      }
    }
    

    Then you would just need to make a list of all the buttons you need to pass to your color changer.

    List<Button> buttons = new ArrayList<Button>();
    buttons.add((Button)findViewById(R.id.one));
    //add any more buttons
    

    Just be aware, that theming and styling in Android allows you to accomplish a great deal of these kinds of effects. I would be sure you exhausted your efforts there before turning to a code solution.

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

Sidebar

Related Questions

in my app i have activity with XML layout, i want to build an
i have some problems in using the date picker from xml layout. in my
I have a about screen that has some buttons, but I keep getting NullPointerException
I have an activity with the following layout. So in this screen, initally the
I have login- and game-layout in my activity. I would use AndroidAnnotations in my
I have implemented a custom view within another activity into a XML layout. The
I have imageView inside a relative layout. And when i create the activity i
I had already setup the buttons and the layout properly, but I'm having an
What I have here real simple activity with two buttons. When you press each
I have a main.xml file describing the layout of my main activity: <?xml version=1.0

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.