Details about the drawable state attributes of Android

Source: Internet
Author: User

When defining a drawable, we can use the drawable object defined in xml. It enables an image to display different patterns in different States. For example, a Button has the options of pressed, focused, or other States. By using the state list drawable, you can provide different images for each status.

Let's first look at an example:

   
       
   
       
   
        
   
        
   
    
   


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

   


Android: drawable: place a drawable Resource
Android: whether to press state_pressed, such as a button to touch or click.
Android: state_focused indicates whether to obtain the focus. For example, you have selected a text box.
Android: state_hovered: whether to hover the cursor. It is usually the same as the focused state. It is a new feature of 4.0.
Android: state_selected is selected. It is not exactly the same as the focus state. When a list view is selected, its child components may be selected through the direction keys.
Android: whether the state_checkable component can be checked. For example, RadioButton can be checked.
Android: state_checked has been checked. For example, a RadioButton can be checked.
Android: state_enabled can accept touch or click events
Android: state_activated is activated (this is not a special example)
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 there are multiple items, the program will automatically match from top to bottom, and the first matching will be applied. (Not through the best match)
If an item does not have any state description, it can be matched by any State.

For more information, see the official API ~! Http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

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.