简体   繁体   English

Android开关按钮错误:资源不是可绘制对象(颜色或路径)

[英]Android Switch Button error: Resource is not a Drawable (color or path)

I'm working on an existing Android application that runs pretty well, and I'm trying to implement the Switch Button. 我正在开发一个运行良好的现有Android应用程序,并且正在尝试实现“切换按钮”。 The application has a theme with styles for the buttons: 该应用程序有一个带有按钮样式的主题:

<item name="android:buttonStyle">@style/ButtonMain</item>
<item name="android:button">@style/ButtonMain</item>

If I run my application and go to the screen with the Switch button, it crashes with the following error: 如果我运行我的应用程序并使用“切换”按钮转到屏幕,它将崩溃并显示以下错误:

Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0e0011 a=1 r=0x7f0e0011}

The rest of the application runs well and the normal buttons are well styled. 该应用程序的其余部分运行良好,普通按钮的样式也不错。 If I comment the two lines from the theme for the button, it works well either for the Switch and Button. 如果我将按钮主题的两行注释掉,那么它对于Switch和Button都适用。

My drawable resource exists as it's working for the button but not the Switch... Does anyone has an idea? 我的可绘制资源存在,因为它正在为按钮工作,但没有为Switch工作。有人有想法吗? Is it possible to revert the theme for a specific widget? 是否可以还原特定小部件的主题? I tried with: 我尝试过:

android:theme="@android:style/Theme.Holo.Light.DarkActionBar"

but I still get my error, the Switch wants to get the button style from my theme. 但是我仍然遇到错误,Switch希望从主题中获取按钮样式。

Thanks! 谢谢!

I have the exact same error. 我有完全一样的错误。

I removed my "android:button" style which just pointed to an empty style that extended a holo style and this fixed it. 我删除了我的“ android:button”样式,该样式仅指向扩展了全息样式的空样式,并对此进行了修复。 I am assuming if extending android:button you will need to set some styles there. 我假设如果扩展android:button,则需要在那里设置一些样式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM