"Turn" Android drawable state various properties

Source: Internet
Author: User

The Drawable object that we can define through XML when we define a drawable. It allows a picture to display different patterns in different states, such as a button, it has a pressed,focused, or other state, and by using the state list drawable, you can provide a different picture for each of the States.

Let's look at an example:

XML file saved at res/drawable/button.xml :

[Java]View PlainCopy
  1. <?xml version="1.0" encoding="Utf-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android" >
  3. <item android:state_pressed="true" android:state_enabled="true" android:state_window_focused=" False "
  4. android:drawable="@drawable/button_pressed"/> <!--pressed,enable Multiple properties --
  5. <item android:state_focused="true"
  6. android:drawable="@drawable/button_focused"/> <!--focused --
  7. <item android:state_hovered="true"
  8. android:drawable="@drawable/button_focused"/> <!--hovered --
  9. <item android:drawable="@drawable/button_normal"/> <!-- default ---
  10. </selector>


This layout XML applies the state list drawable to a Button:

[Java]View PlainCopy
    1. <BUTTON&NBSP;&NBSP;
    2.     android: Layout_height= "wrap_content" &NBSP;&NBSP;
    3.      android:layout_width= "wrap_content" &NBSP;&NBSP;
    4.      android:background= "@drawable/button" &NBSP;/>&NBSP;&NBSP;



Android:drawable put a drawable resource
Whether the android:state_pressed is pressed, such as a button touch or click.
Whether the android:state_focused has the focus, such as when a user selects a text box.
Android:state_hovered the cursor is hovering, usually the same as focused state, which is a new feature of 4.0
Android:state_selected is selected, and it is not exactly the same as the focus state, when a list view is selected, the various sub-components within it may be selected by the arrow keys.
Whether the Android:state_checkable component can be check. For example: RadioButton can be check.
Android:state_checked was checked, such as: A RadioButton can be check.
Android:state_enabled can accept touch or click events
Android:state_activated is activated (this trouble for example, not special)
Android:state_window_focused whether the application is in the foreground, when a notification bar is pulled down or a dialog box pops up, the application is not in the foreground.

Note: If you have more than one item, the program will automatically match from top to bottom, and the first match will be applied. (not through Best Bets)
If an item does not have any status descriptions, it will be able to be matched by any one of the states.

Please see the official API, which is written in more detail! Http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

from:http://blog.csdn.net/leasystu/article/details/7250885

"Go" Android drawable State individual properties

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.