| 279 | } |
| 280 | |
| 281 | private Drawable getSelector(Tag tag) { |
| 282 | if (tag.background != null) |
| 283 | return tag.background; |
| 284 | |
| 285 | StateListDrawable states = new StateListDrawable(); |
| 286 | GradientDrawable gdNormal = new GradientDrawable(); |
| 287 | gdNormal.setColor(tag.layoutColor); |
| 288 | gdNormal.setCornerRadius(tag.radius); |
| 289 | if (tag.layoutBorderSize > 0) { |
| 290 | gdNormal.setStroke(Utils.dipToPx(getContext(), tag.layoutBorderSize), tag.layoutBorderColor); |
| 291 | } |
| 292 | GradientDrawable gdPress = new GradientDrawable(); |
| 293 | gdPress.setColor(tag.layoutColorPress); |
| 294 | gdPress.setCornerRadius(tag.radius); |
| 295 | states.addState(new int[]{android.R.attr.state_pressed}, gdPress); |
| 296 | //must add state_pressed first,or state_pressed will not take effect |
| 297 | states.addState(new int[]{}, gdNormal); |
| 298 | return states; |
| 299 | } |
| 300 | |
| 301 | |
| 302 | //public methods |