开发者

Changing background image when tapped -- Android

开发者 https://www.devze.com 2023-02-18 10:42 出处:网络
I am trying to write a basic app that when the phone is tapped anywhere开发者_JS百科, the background image changes.

I am trying to write a basic app that when the phone is tapped anywhere开发者_JS百科, 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?


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号