Change background image while listening - Android

I'm trying to write a basic application that, when the phone is tapped anywhere, changes the background image. If someone could connect me with a good tutorial on how to do this or have some code snippets that I could use, it would be very helpful.

Is it also possible to encode this in xml or do it in java?

+3
source share
1 answer

Add the 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 work

public void onClick(View v) {
    v.setBackgroundResource(R.drawable.someDrawable);
}
+3
source

All Articles