Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing background image when tapped -- Android

I am trying to write a basic app that when the phone is tapped anywhere, the background image changes. If anyone could link me to a good tutorial on how to do this or have some code snippits i could use it would be greatly appreciated.

Also is this possilble to code this in the xml or does it need to be done in java?

like image 552
Johnston Avatar asked Mar 25 '26 20:03

Johnston


1 Answers

Add an onClick event to the layout and in the listener, change the background.

in xml

<LinearyLayout android:layout_height="FILL_PARENT"
    android:layout_width="FILL_PARENT" 
    android:onClick="onClick" />

and in your activity

public void onClick(View v) {
    v.setBackgroundResource(R.drawable.someDrawable);
}
like image 190
Robby Pond Avatar answered Mar 27 '26 10:03

Robby Pond



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!