Android切换按钮错误:资源不是可绘制的(颜色或路径)

时间:2022-11-21 12:24:47

I'm working on an existing Android application that runs pretty well, and I'm trying to implement the Switch Button. The application has a theme with styles for the buttons:

我正在开发一个运行良好的Android应用程序,我正在尝试实现Switch按钮。该应用程序的主题为按钮的样式:

<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:

如果我运行我的应用程序并使用Switch按钮进入屏幕,它会崩溃,出现以下错误:

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.

应用程序的其余部分运行良好,普通按钮的样式也很好。如果我从按钮的主题中注释这两行,那么它对开关和按钮都很有效。

My drawable resource exists as it's working for the button but not the Switch... Does anyone has an idea? 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.

但我还是得到了我的错误,开关想从我的主题中获得按钮样式。

Thanks!

谢谢!

1 个解决方案

#1


0  

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. I am assuming if extending android:button you will need to set some styles there.

我去掉了我的“android:button”样式,它只是指向一个扩展了holo样式的空样式,这个修改了它。我假设如果扩展android:按钮,你需要设置一些样式。

#1


0  

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. I am assuming if extending android:button you will need to set some styles there.

我去掉了我的“android:button”样式,它只是指向一个扩展了holo样式的空样式,这个修改了它。我假设如果扩展android:按钮,你需要设置一些样式。