Imagebutton, a common android basic control

Source: Internet
Author: User
    • You can use the Android: src attribute or setimageresource (INT) method to set imagebutton images.
    • If the image displayed by imagebutton cannot completely overwrite the background color, use imagebutton to set the background color to another image or directly set it to transparent.

<? XML version = "1.0" encoding = "UTF-8"?>
<Tablelayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical" Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Tablerow Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content">
< Textview Android: Id = "@ + ID/tvemail" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: ellipsize = "end"
Android: autolink = "email" Android: text = "email \ n (such as sunnychuh@163.com)"/>
< Edittext Android: Id = "@ + ID/etemail" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: hint = "Enter your email address"
Android: selectallonfocus = "true"/>
</Tablerow>
<Tablerow Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content">
<Textview Android: Id = "@ + ID/tvphone" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: ellipsize = "Middle"
Android: autolink = "email" Android: text = "phone \ n (e.g., 1234567890):"/>
<Edittext Android: Id = "@ + ID/etphone" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: maxwidth = "160px"
Android: phonenumber = "true" Android: singleline = "true"
Android: selectallonfocus = "true"/>
</Tablerow>
<Tablerow Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content">
<Button Android: Id = "@ + ID/button01" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: gravity = "right"
Android: text = "display"/>
< Imagebutton Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: src = "@ drawable/myselector"
Android: Background = "@ color/ABC"/>
</Tablerow>
</Tablelayout>

Here, Android: SRC of imagebutton creates myselector. XML in drawable-mdpi:

<? XML version = "1.0" encoding = "UTF-8"?>
<Selector xmlns: Android = "http://schemas.android.com/apk/res/android">
<Item Android: state_pressed = "false" Android: drawable = "@ drawable/img01"/>
<Item Android: state_pressed = "true" Android: drawable = "@ drawable/img02"/>
</Selector>

After you press imagebutton, the following information is displayed:

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.