Selector的一个坑

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yinzhong39/article/details/47376045

创建selector时,有个小坑,就是默认没有指明任何状态的item必须写在末尾。因为系统会拿第一个item去匹配当前状态,如果没有指明state的item放在第一个的话,会匹配任何state,会造成与实际期望的效果不符合的情况。
参考:http://developer.android.com/intl/zh-cn/guide/topics/resources/drawable-resource.html#StateList

Note: Remember that Android applies the first item in the state list that matches the current state of the object. So, if the first item in the list contains none of the state attributes above, then it is applied every time, which is why your default value should always be last (as demonstrated in the following example).

展开阅读全文

没有更多推荐了,返回首页