Issue
What is the difference between <selector>
and <shape>
in android? When to use <selector>
, and <shape>
?
Solution
What is the difference between
<selector>
and<shape>
in android?
Other than being XML used in layout resources, they are unrelated.
When to use
<selector>
, and<shape>
?
<shape>
is a way to define a ShapeDrawable
in a drawable resource, for representing rectangles and ovals with various borders and fills.
<selector>
is a way to define a StateListDrawable
in a drawable resource, for indicating other drawables to use based on the state of the widget that is applying this StateListDrawable
.
So, in the context of a button, the <selector>
would say what to use for the normal background, the pressed background, the disabled background, and so on. <shape>
would be used to provide the actual background for one of those states.
You can read more about the different drawable resource types in the documentation.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.