-3

Hi guys as i make my quiz application for my thesis i think of adding a shop to buy different THEMES.first i need to know how to set a background using a button?

@Override
public void onClick(View v) {
switch(v.getId())

case R.id.btTheme:
                 //no idea :D


            break;

1 Answers1

0

Hello Tj Estrella Manzano RelativeLayout rel;

in button1.setOnClickListener write this rel=(RelativeLayout)findViewById(R.id.rel);

rel.setBackgroundColor(Color.BLUE);

This is the code to change the background color.

if you want to change the background image then you have to create a final Drawable

Drawable drawable = res.getDrawable(R.drawable.a); // a is the name of image stored in Drawable folder

and then rel.setBackground(drawable);

Avinash Ajay Pandey
  • 1,497
  • 12
  • 19