title: Android/Java: how to define a specific class usable in an xml layout file?
body: <p>I am not satisfied with the default ImageButton item provided with the Android SDK and I want to define my own ImageButton (lets call it SquareImageButton) which extends from ImageButton.</p>
  
  <p>I consequently create a class like this:</p>
  
  <pre><code>public class SquareImageButton extends ImageButton {
  
  // Here I want to include some code which would for example
  // force the width of the SquareImageButton to be equal to its height
  // And many other things !!!
  
  }
  </code></pre>
  
  <p>Now I want to use this SquareImageButton in xml like I would use a usual ImageButton. For example like this:</p>
  
  <pre><code>&lt;SquareImageButton
              android:id="@+id/speakButton"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:src="@drawable/icon_rounded_no_shadow_144px"
             /&gt;
  </code></pre>
  
  <p>How should I write in my SquareImageButton class to do this ? Any other things to do to be able to include my SquareImageButton in my xml with no compile or runtime errors ?</p>
  
  <p>Thanks !!!</p>