How to Use imagebutton in Android

Source: Internet
Author: User

Imagebutton can be used flexibly in Android, either in. Java or in. XML, but it is more advantageous in. xml. Code The above two methods are described:

1. One is in the code
Software Development
Your own images

M_imagebutton.setimagedrawable (getresources (). getdrawable (R. drawable. my_button ));

Images provided by the system

M_imagebutton.setimagedrawable (getresources (). getdrawable (Android. R. drawable. sym_call_incoming ));

2. One is in an XML file.

Your own images

Android: src = "http://www.cnblogs.com/@drawable/ic_media_play"

Images provided by the system

Android: src = "@ Android: drawable/sym_call_incoming"

3. The background image of the specified button, including state_pressed and state_focused, represents the status when you press down and focus stays (controlled by direction keys, etc.).

The default value is false. The following figure shows the background image when the image is pressed.
Arrears
Add in Main. XML,

Android: Background = "@ drawable/button_add_x.

Add a button_add_x under Res/drawable. XML file

<? XML version = "1.0" encoding = "UTF-8"?>

<Selector xmlns: Android = "http://schemas.android.com/apk/res/android">

<Item Android: state_pressed = "true"

Android: drawable = "@ drawable/ic_media_select"/>

</Selector>

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.