Thursday 9 August 2012

Change background with button (Android)

package com.test.background;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;


public class appTest extends Activity {

    private Button btn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        BtnListener();
   }

   private void BtnListener() {
        Button btn = (Button) findViewById(R.id.button1);
        btn.setOnClickListener(new OnClickListener(){
            public void onClick(View arg0){             
                RelativeLayout ll = (RelativeLayout)findViewById(R.id.rootRL);
                ll.setBackgroundResource(R.drawable.new_background);
            }
        });  
    }
}

No comments:

Post a Comment