Reuse scheme of declare styleable attribute of custom controls in Android
Recently, I came into contact with Android custom controls, involving attributes in custom XML. It is actually very simple, but I found that the code is not perfect. That is, I found attribute redundancy in the file attribs.xml, so I wondered whether there are methods such as attribute inheritance or include. This article will record attribute reuse in declare styleable
Imperfect code
As in the above code, there are repeated attribute declarations in the styleable of extextview and exedittext. Although the above can work, it always feels that the writing is not professional, so we look for optimization methods
Is that okay
Try to specify a parent for declare styleable, as shown in the following code
Ultimate answer
In fact, we can declare the attributes to be used multiple times before declare styleable. In the declare styleable node, just call. The specific code is as follows
Extended reading
http://stackoverflow.com/questions/18827875/how-to-declare-several-stylable-attributes-with-the-same-name-for-different-tags