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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:51:21+00:00 2026-06-13T06:51:21+00:00

I am new to Android and Java but have managed to teach myself and

  • 0

I am new to Android and Java but have managed to teach myself and find most answers to questions on stackoverflow without needing to ask questions. Until now….

Here goes, I have many colored buttons which, when clicked, change color to a range of different colors.

There are many buttons defined for example as:

<Button
   android:id="@+id/button17"
   android:layout_width="0dp"
   android:layout_height="fill_parent"
   android:layout_weight="1"
   android:background="@drawable/orange_button"
   android:gravity="center"
   android:onClick="onClick" />

Could someone please advise me how to change the android:background using code to change the above example to yellow, for example, when the button is clicked.

In the code below clickedButton is the ID of the button for which I need to change the background.

public void onClick(View v) {
    int id=v.getId();
    String clickedButton = getResources().getResourceEntryName(id);

    Change button to Yellow here??

    // Temporary code below to check which button was pressed
    // and convert its number to an integer to eventually access an array

    final TextView tvGameTimer = (TextView) findViewById(R.id.tvGameTimer);
    int buttonNumber = Integer.parseInt(clickedButton.substring(6,8));
    tvGameTimer.setText("" + buttonNumber);

    }

I am using custom button styles to define the button colors:

res/drawable/yellow_button.xml
res/drawable/blue_button.xml
res/drawable/red_button.xml
res/drawable/orange_button.xml
res/drawable/green_button.xml

For now I just need to work out how to change the button from Orange to Yellow. I can then add the logic to change the colors as and when the app requires.

Many thanks for any help.

  • 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-13T06:51:22+00:00Added an answer on June 13, 2026 at 6:51 am

    I am supposing that the onClick method you post is of the same Button whose background you are trying to change. Use this code.

      v.setBackgroundResource(R.drawable.yellow_button);
    

    If onClick is not the method of the same button then, use

      findViewById(R.id.button17).setBackgroundResource(R.drawable.yellow_button);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Android & Java programming but have been programming in .NET for
I am a bit new with android but I have some java experience. So
I am very new to Android development and Java. Have read around but I'm
I am new at android development and java programming, but I have decided to
I'm pretty new to Android development, but I have some experience with Java and
I'm new to Java but not to programming. I'm reading the book Beginning Android
I'm fairly new to Java and Android programming in general but I would like
I am new to Android and Java programming. I have a class which implements
I'm fairly new to Java & Android, so I have little idea what I
I'm very new to Android . I've used Java before but not for around

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.