我对 Android SDK 提供的默认 ImageButton 项目不满意,我想定义我自己的 ImageButton(我们称之为 SquareImageButton),它从 ImageButton 扩展而来。
因此,我创建了一个这样的类:
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 !!!
}
现在我想在 xml 中使用这个 SquareImageButton,就像我使用通常的 ImageButton 一样。例如像这样:
<SquareImageButton
android:id="@+id/speakButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/icon_rounded_no_shadow_144px"
/>
我应该如何在我的 SquareImageButton 类中编写来做到这一点?为了能够将我的 SquareImageButton 包含在我的 xml 中而没有编译或运行时错误,还有其他事情要做吗?
谢谢 !!!