android自定义控件inflate报错view.inflate.exception

在尝试动态使用封装的KeyboardView时遇到view.inflate.exception错误。问题源于xml中使用了与android内置控件冲突的<KeyboardView>标签,改为自定义类名后问题仍未解决。最终发现需要覆盖FrameLayout的其他两个构造方法,完成这些修改后,异常消失,加载正常。
摘要由CSDN通过智能技术生成

为了方便动态使用自定义KeyboardView, 对其进行了封装

public class KeyboardView extends FrameLayout {
	private Context mcontext;
	
	public KeyboardView(Context context) {
		super(context);
		
		mcontext = context;
		initComponents();
	}
}	

但是每次在MainActivity中执行到加载的时候:

keyboardView = (KeyboardView)stub.inflate();


就会报错: view.inflate.exception, 首先发现在xml中自己直接使用了:

<KeyboardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_gravity="bottom" >


 <KeyboardView /> 标签, 而androd有个自带的控件:

android.inputmethodservice.KeyboardView, 所以将xml中标签改成了:

<com.yzh.lockpri2.widget.KeyboardView xmlns:android="http://sch
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值