Subclass Button with Android : lots of errors

后端 未结 2 1897
旧巷少年郎
旧巷少年郎 2021-01-26 16:09

I tried to subclass Button , but I have a lot of errors when launching my project. Could you have a look and tell me how to fix this? (I\'ve got maybe 50 errors com

相关标签:
2条回答
  • 2021-01-26 16:34

    rename

    <MyButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/myb"
        android:tag="tag"
         />
    

    to a fully qualified Namespace

    <namespace.from.button.MyButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/myb"
        android:tag="tag"
         />
    
    0 讨论(0)
  • 2021-01-26 16:38

    Using the fully-qualified name for the element in the XML layout does not work if your Button subclass is an inner class. If this is the case, you need to add a class attribute and use the generic view for the element name.

    <view
        class="my.project.name.MyProjectActivity$MyButton"
        ...
    

    http://developer.android.com/guide/topics/ui/custom-components.html

    0 讨论(0)
提交回复
热议问题