Discard the Selector file and implement text color, background color, border rounded corners, background image, foreground image configuration directly in the layout file.

1. Gradle adds references

The compile 'com. Wei. Android. Lib: colorview: 1.2.0'Copy the code

2. Extended View

ColorButton
ColorEditText
ColorImageView
ColorLinearLayout
ColorRelativeLayout
ColorTextView
ColorView
Copy the code

3. Extended attributes

app:textColorNormal="#FFFFFF" app:textColorPressed="#FFFFFF" app:textColorSelected="#FFFFFF" app:textColorChecked="#FFFFFF" app:textColorUnable="#FFFFFF" app:backgroiundColorNormal="#FFFFFF" app:backgroiundColorPressed="#FFFFFF" app:backgroiundColorSelected="#FFFFFF" app:backgroiundColorChecked="#FFFFFF" app:backgroiundColorUnable="#FFFFFF" app:backgroundDrawableNormal="@drawable/pic_test" app:backgroundDrawablePressed="@drawable/pic_test" app:backgroundDrawableSelected="@drawable/pic_test" app:backgroundDrawableChecked="@drawable/pic_test" app:backgroundDrawableUnable="@drawable/pic_test" app:srcDrawableNormal="@drawable/pic_test" app:srcDrawablePressed="@drawable/pic_test" app:srcDrawableSelected="@drawable/pic_test" app:srcDrawableChecked="@drawable/pic_test" app:srcDrawableUnable="@drawable/pic_test" app:borderColorNormal="#FFFFFF" app:borderColorPressed="#FFFFFF" app:borderColorSelected="#FFFFFF" app:borderColorChecked="#FFFFFF" app:borderColorUnable="#FFFFFF" app:borderWidth="2dp"  app:borderDashWidth="10dp" app:borderDashGap="10dp" app:cornerRadius="10dp" app:cornerRadiusTopLeft="10dp" app:cornerRadiusTopRight="10dp" app:cornerRadiusBottomRight="10dp" app:cornerRadiusBottomLeft="10dp"Copy the code

3. Attributes

1. The xxxNormal attribute is universal. After Normal is set, the other four attributes follow Normal by default. When the background image and the background color are set together, the background image overwrites the background color. 3. Call view.getxxHelper ().setxxx () to update a property;Copy the code

4. Develop notes

1. When enlarging the border, you need to rebuild the background object; otherwise, the background border will not be drawn correctly.

5. Small defects in the library

1. When the four rounded corners have different values, the background rendering is somewhat inaccurate. The larger the rounded corners are, the more obvious they are.

6. Version records

V1.2.02017.12.12 Release 1.2.0

License

Licensed under the MIT License, see the LICENSE for copying permission.