您的位置:首页 > 移动开发 > Android开发

Error inflating class android.widget.CheckBox

2016-03-18 23:44 351 查看
在android开发中界面使用到checkbox这个控件的时候遇到了文章标题的错误,百度google都查不到我想要的答案.

我的代码没有问题,就是一个checkbox控件,然后在activity中实例化并使用它的监听器,在4.4的版本中运行出现闪退,而在5.0的版本中就可以完美运行,真是个奇怪的错误.

最后通过查看官方文档发现,在控件这一节,有个声明

You can control exactly how your controls are styled using a theme that you apply to your entire application. For instance, to ensure that all devices running Android 4.0 and higher use the Holo theme in your app, declare android:theme="@android:style/Theme.Holo" in your manifest's <application> element.


大致的意思就是,你可以控制你的控件使用什么主题,那估计是主题不兼容的问题,用文中提到的android:theme=”@android:style/Theme.Holo”

主题将manifest中系统默认生成的主题替换掉,果然可以在4.4的版本中运行了.

如果大家遇到的也是这个问题,那不妨试试这个方法,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: