在res/values/attrs.xml中写下如下代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="TileView">
<attr name="tileSize" format="dimension"></attr>
</declare-styleable>
</resources>
然后在TileView.java文件中如下:
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TileView);
mTileSize = a.getDimensionPixelSize(R.styleable.TileView_tileSize, 12);
a.recycle();
结果styleable处出现红色下划波浪线,提示错误为:styleable cannot be resolved or is not a field
------解决思路----------------------
没有import R所在的包。