Study Notes for Android: imagebutton

Source: Internet
Author: User

Display an image button that can be clicked by users. By default, imagebutton looks like a normal button and changes the background color in different States (such as pressing. <Imagebutton>
Android: src attribute of the XML element or setimageresource (INT) method.

 

To indicate different button states (Focus, selection, etc.), you can define different images for various States. For example, define a blue image as the default image, a yellow image as the image displayed when the current focal point is obtained, and a yellow image as the image displayed when the button is pressed. This can be done in a simple way-the XML "selector." configuration is as follows:

Save the above XMLres/drawable/Folder (Note: The file name is case sensitive !), Set the file name as a parameter to
Android: src attribute (Note: for example, if the XML file name is myselector. XML, set this attribute to "@ drawable/myselector" and set Android: background as well, but the effect is not the same ). Android will automatically search for the corresponding image in XML for Display Based on the button status change.

<Item> the order of elements is very important, because it is used to determine whether it is applicable to the current button status, which is why the specified image in the normal (default) status is placed at the end, it will only be used after both pressed and focused fail to judge. (Note: for example, when a button is pressed, the focus is obtained at the same time, but the focus is not necessarily pressed. Therefore, we will search for the focus in order. If the focus is found properly, we will not look down. If the button is clicked, the first one will be selected and will not be found later .)

 

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="ImageButton"/>    <ImageButton        android:id="@+id/image1"        android:layout_width= "wrap_content"        android:layout_height="wrap_content"        android:src= "@drawable/macos01"/></LinearLayout>

 

After clicking

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.