【发布时间】:2016-04-17 22:07:10
【问题描述】:
我似乎有一个我不知道如何用 Android Studio 解决的问题。代码在 Eclipse 上工作,奇怪的是它也工作在 Android Studio 的设计预览窗口,但当我在任何真实设备上执行应用程序时不起作用。
我遇到的问题是可绘制文件夹,其中我有一个选择器 xml 和一个形状 xml 文件。在我的布局中,我将按钮的背景设置为选择器 xml 文件。我注意到选择器 xml 文件中有一个非常烦人的带有感叹号的红色圆圈,我在其中将可绘制对象指定为形状 xml 文件。它没有说明问题是什么,如果有的话。它看起来就像下图:
这是我的文件的代码:
bshape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#FFAA33"/>
<corners android:radius="5dp" />
</shape>
button.xml(选择器)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Normal state of button -->
<item
android:state_enabled="true"
android:drawable="@drawable/bshape" />
</selector>
我的布局(相对布局)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Button Test"
android:textColor="#000000"
android:background="@drawable/button"/>
</RelativeLayout>
我已确保 xml 文件具有 .xml 扩展名。我注意到几篇关于缺少 xml 文件中的扩展名的帖子。 这真的让我发疯。我花了大约 3 个小时试图解决这个问题,但我只是不知道它可能是什么。非常感谢任何帮助。提前谢谢你!
【问题讨论】:
-
您是否尝试构建应用程序?
-
是的,我做到了。我清理了项目,删除了生成的文件,重建了项目,问题仍然存在。
-
如果您使用的是 Windows 机器或 Linux。尝试将光标移动到 bshape 并按 ALT+Enter 它将为您提供有关如何修复它的建议
-
我正在使用 Windows,我还应该声明我的应用程序的最低 SDK 为 15,目标为 23。当我按 ALT+Enter 时,我得到一个菜单,上面写着:“在其他配置中覆盖资源。 ..”
-
对不起,我无法找出问题所在。但最后一个建议是在阅读此错误之后。尝试给这两个文件一个不同的名称和干净的构建。
标签: android xml button drawable