How can I create my custom properties on xml for Android?

前端 未结 4 606
死守一世寂寞
死守一世寂寞 2020-12-04 17:59

We have in our project a keyboard with \"Key\" elements, this Key elements have attributes such as android:codes=\"119\", android:keyLabel=\"w\" and so on.

My questi

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 18:37

    For any other purpose, declaring a custom property in the XML file can be retrieve with attrs constructor parameter.

    In my case I reuse a preference custom dialog, and set things like that:

    
    
    
        
    
    

    Then in my class contructor:

    public CustomView(Context context, AttributeSet attrs) {
        String bar = attrs.getAttributeValue(null, "foo");
        Log.d("CustomView", "foo=" + bar);
    }
    

提交回复
热议问题