Android‎ > ‎

Creating Custom Views

posted Feb 22, 2012, 2:31 AM by Akash Khaitan   [ updated Mar 9, 2013, 7:33 AM ]
Custom views(including buttons,lists,text..etc) can very simply be created in the android.
There are several possible ways for doing the same but I use what I call is the "JAVA Extend & XML parse" method

  1. Create a separate custom class extending the view(Button,EditText...etc) you want
  2. Override the methods(onDraw,onMeasure,setMeasuredDimension(),..etc) according to the requirement
  3. In the XML layout where you want the custom view, use as shown below
             <com.soulastral.custom.CustomText                //location of the custom class(with package)
            android:text="@string/hello"                                  //desc
            android:layout_width="wrap_content"                     //desc
            android:layout_height="wrap_content">                  //desc
            </com.soulastral.custom.CustomText>              //Closing custom class 
See the simple attached program(
see layout file and both the classes

For More details visit

Akash Khaitan,
Feb 22, 2012, 2:31 AM