开发者

Changing background image when tapped -- Android

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜