我正在尝试为我的 android 应用程序创建自定义按钮类
public class TicTacButton extends Button
我已经在内部设置了所有构造函数TicTacButton
并创建了自定义方法和属性。在我的主要活动中,我尝试将按钮初始化为
TicTacButton btn = (TicTacButton) findViewById(R.id.button1);
我得到一个
java.castClassException。android.widget.Button 不能转换为 com.example.tictactoetitan.TicTacButton
我尝试将我的 xml 文件更改为
<TicTacButton
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button1"
android:layout_toRightOf="@+id/button1" />
它没有用。