显示不支持的自定义属性的错误

Show error for unsupported custom attribute

提问人:Angad Singh 提问时间:9/3/2016 最后编辑:Angad Singh 更新时间:9/3/2016 访问量:76

问:

我正在开发一个 Android 库,它制作了不同形状的按钮。按钮的 XML 如下所示:

<com.singh.daman.mybutton.ShapedButton
        android:id="@+id/round"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:fill_color="@color/colorPrimaryDark"
        app:button_type="round_rectangle"
        app:stroke_color="@color/colorAccent"
        app:stroke_width="12sp"
        app:text="Round Rectangle"
        app:text_size="16sp"
        app:text_color="#ffff"
        android:layout_gravity="center"
        android:background="@null" />

其中属性具有不同的值,如矩形、星形、圆形和圆形矩形。app:button_type="round_rectangle"

只有 Lollipop 及以上的 android 版本支持该类型。round_rectangle

所以,当库用户设置为并且应用程序最低 android 版本小于 Lollipop 时,我想显示一个错误,它只支持 api 21 及更高版本,我该怎么做?button_typeround_rectangle

Android XML 错误报告

评论


答:

1赞 Jeffrey Blattman 9/3/2016 #1

您需要一个自定义 lint 规则。我从来没有这样做过,但谷歌有关于这个话题的文章。http://tools.android.com/tips/lint-custom-rules