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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:28:11+00:00 2026-06-06T19:28:11+00:00

I have a simple program which is able to change the background color after

  • 0

I have a simple program which is able to change the background color after clicking a button, but it does not work

public class ChangeBackgroundActivity extends Activity {
/** Called when the activity is first created. */
    Button blueButton;
    LinearLayout myLO;
    @Override
   public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        myLO=(LinearLayout)findViewById(R.layout.main);
        blueButton=(Button)findViewById(R.id.button1);
        blueButton.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
            // TODO Auto-generated method stub
            myLO.setBackgroundColor(0x0000FF); //blue color code #0000FF    
        }
    });
    }
}
  • 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-06T19:28:12+00:00Added an answer on June 6, 2026 at 7:28 pm

    Try With this,

    main.xml

       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/myLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
    
            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="64dp"
                android:layout_marginTop="71dp"
                android:text="changeColor" />
    
        </LinearLayout>
    

    ChangeBackgroundActivity.java

    public class ChangeBackgroundActivity extends Activity {
    /** Called when the activity is first created. */
        Button blueButton;
        LinearLayout myLO;
        @Override
       public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            myLO=(LinearLayout)findViewById(R.id.myLayout);
            blueButton=(Button)findViewById(R.id.button1);
            blueButton.setOnClickListener(new OnClickListener() {
    
                public void onClick(View arg0) {
                // TODO Auto-generated method stub
                myLO.setBackgroundColor(Color.BLUE);
    
            }
        });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple program which tries to decode an encoded URL. But for
I have avery simple program which uses MediaPLayer. I am new to java and
Below, I have a simple program which uses the CImg library (http://cimg.sourceforge.net/) which iterates
I have a simple Delphi program that I'm working on, in which I am
I have been trying to create a simple program with Python which uses OpenCV
In my google maps program I have simple KML parser which retrieve only coordinates
I have a simple program to check if a port is open, but I
I have a simple Ruby program which takes the command line arguments and posts
I am working on a simple program which requires me to be able to
I have a simple c++ program I am trying to debug, but gdb cannot

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.