【发布时间】:2017-11-13 03:45:32
【问题描述】:
我想在 Android Studio 中创建一个选择器。我在 res.layout 文件夹中创建了一个名为“button_hover.xml”的文件。
button_hover.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content" android:layout_width="wrap_content">
<item android:state_focused="true" android:drawable="@drawable/bg1.png"/>
<item android:state_pressed="true" android:drawable="@drawable/bg2.png" />
<item android:drawable="@drawable/bg3.png" />
</selector>
bg1.png, bg2.png, bg3.png 存在于我的drawable文件夹中,我可以使用Ctrl+Space来调用它们,但是当我运行应用程序时,控制台显示错误:
Error:(5, 58) No resource found that matches the given name (at 'drawable' with value '@drawable/bg1.png').
Error:(6, 58) No resource found that matches the given name (at 'drawable' with value '@drawable/bg2.png').
Error:(7, 29) No resource found that matches the given name (at 'drawable' with value '@drawable/bg3.png').
我该如何解决这个问题?
【问题讨论】:
-
改用
@drawable/bg1,丢掉.png -
从使用drawable的地方删除.png扩展名
标签: android android-layout android-drawable android-selector