This class is mainly used to display an image button that can be clicked by users. Android: src and setImageResource () of the XML element of <ImageButton> can be used to specify the image to be displayed by the button. By default, it is a normal button, so you can set the background color to transparent, only display the image you want to display, not the background. 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-by configuring "selector. XML" in xml, for example:
<span style="font-family:Microsoft YaHei; font-size:14px"><span style="white-space:pre"> </span><selector xmlns:android="http://schemas.android.com/apk/res/android"> <span style="white-space:pre"> </span><item android:state_pressed="true" <span style="white-space:pre"> </span>android:drawable="@drawable/btn_pressed" /> <span style="white-space:pre"> </span><item android:drawable="@drawable/btn_normal"/></span>
<span style="font-family:Microsoft YaHei; font-size:14px"><span style="white-space:pre"> </span></selector></span>
Save the preceding XML file to the res/drawable/folder and set the file name as a parameter to the android: src attribute of ImageButton (Note: for example, the xml file name is myselector. in xml format, set it to "@ drawable/myselector" and set android: background, 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 is used only after the expression fails.