<项目>标签需要一个'绘制'属性 [英] <item> tag requires a 'drawable' attribute

查看:91
本文介绍了<项目>标签需要一个'绘制'属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想很干脆的风格按钮。我只是想用文本时,点击时没有pressed,白色与蓝色的文字是蓝色。

I am trying to very simply style a Button. I just want it blue with with text when not pressed, and white with blue text when clicked.

我试图用一种风格和选择这样做。

I tried to do this with a style and a selector.

在我的布局,我有这样的按钮

In my layout I have this Button:

 <Button
    android:id="@+id/button1"
    style="@style/MyButton"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="@string/login" />

而在 RES /价值/风格我有这样的 styles.xml

<style name="MyButton">
    <item name="android:background">@drawable/btn_background</item>
    <item name="android:textColor">@drawable/btn_textcolor</item>
</style>

当然,这两个选择,在 RES /绘制 btn_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
   <item android:state_pressed="true" android:color="@color/white" />
   <item android:color="@color/SapphireBlue" />
</selector>

btn_textcolor.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" android:color="@color/SapphireBlue" />
    <item android:color="@color/white" />
</selector>

我现在得到的时候我要么运行应用程序或打开布局编辑器的错误是:

The error I get now when I either run the app, or open the layout editor is:

&LT;项目&GT;标签需要一个'绘制'属性。

<item> tag requires a 'drawable' attribute

我理解的消息,但我不有无被拉伸,是很简单的,平坦的按钮。

I understand the message, but I don't have a drawable, is it is a simple, flat button.

我怎样才能创造这样一个简单的按钮?

How can I create such a simple button?

更新根据这个帖子,它应该工作。

推荐答案

试试这个办法,希望这将帮助你解决你的问题。

btn_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/white" android:state_pressed="true"></item>
    <item android:drawable="@drawable/white" android:state_focused="true"></item>
    <item android:drawable="@drawable/SapphireBlue" android:state_enabled="true" android:state_focused="false" android:state_pressed="false"></item>
    <item android:drawable="@drawable/white" android:state_enabled="false"></item>
</selector>

btn_textcolor.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/SapphireBlue" android:state_pressed="true"></item>
<item android:color="@drawable/SapphireBlue" android:state_focused="true"></item>
<item android:color="@drawable/white" android:state_enabled="true" android:state_focused="false" android:state_pressed="false"></item>
<item android:color="@drawable/SapphireBlue" android:state_enabled="false"></item>
</selector>

这篇关于&LT;项目&GT;标签需要一个'绘制'属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆