Android learning ---- use an xml file to set ImageButton to press and play different image implementations

Source: Internet
Author: User

Java code will not be pasted, only the xml file will be mounted,

Method:

1. Put three images in drawable, which are the images that obtain the focus, press the focus, lose the focus, and press the focus, and the natural state (that is, the focus is lost, and the focus is not pressed ). Here you prepare three photos.

2. Create an imagebutton. xml file in the drawable folder. The content in the file is:

<Selector xmlns: android = "http://schemas.android.com/apk/res/android">
<Item
Android: state_focused = "true"
Android: state_pressed = "false"
Android: drawable = "@ drawable/snake"/>
<Item
Android: state_focused = "true"
Android: state_pressed = "true"
Android: drawable = "@ drawable/solitaire"/>
<Item www.2cto.com
Android: state_focused = "false"
Android: state_pressed = "true"
Android: drawable = "@ drawable/solitaire"/>
<Item
Android: drawable = "@ drawable/tunes"> </item>
</Selector>
3. reference the xml file in the layout file:

<ImageButton
Android: id = "@ + id/imgButton"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: background = "@ drawable/image_button"
Author: yanzi1225627
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.