Android provides facility to create our custom view and use it’s custom attribute in XML. For this, first we create a custom view with some custom attribute and then inflate it in XML.
class MyCustomView extends View{
/* variable to hold custom attribute*/
String heading;
/*now initialize object that use for setting the Custom Attribute .Like -Paint,Matrix,Color etc..*/
Paint paint=new paint();
/* Add cunstructor that must takes an AttributeSet object as a parameter,because it is must to inflate the CustomView from a XMl file.*/ /* initialize the string heading With Attribute with hedaing Name in XML*/ } @Override /* override onDraw */ }
|
Now we use this view in XML using Tag <package name.MyCustomView
android:id=@+id/heading1
heading=”Hello This is My Custom Black Heading” />
|