In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use selector in Android". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn how to use selector in Android.
Detailed explanation of Android selector
Foreword:
StateListDrawable is a kind of drawable defined by XML file, which uses several different pictures to render the same figure, and switches through the state of object. For example, a Button has several different states (pressing, getting focus, etc.). In this case, by using state list drawable, you can use different background images in different states.
You can describe state list in a XML file. Add each graph by defining an item element under the root node selector. Different state attributes are used in each item to define the drawable that is not used.
Each time the state changes, the state list is traversed from top to bottom, and the first item that matches the current state will be used-this choice is not to make a "best match" result, but to simply find the first matching state.
Selector is generally used as the background of stateful View, so as to make changes when users operate on View, resulting in View state changes, so that users can perceive the state changes of View.
Official statement
File location: res/drawable/filename.xml
Compiled resource type: StateListDrawable
Resource reference:
In Java: R.drawable.filename
In XML: @ [package:] drawable/filename
Syntax:
For more details, please refer to xsoftlab
Practical use
Let's do a simple example to deal with the background of Button according to the status.
XML file
Selector_ts.xml
Master layout file (activity_main.xml)
At this point, I believe you have a deeper understanding of "how to use selector in Android". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.