Android:为什么我无法使用TextView背景的选择器

Android:为什么我无法使用TextView背景的选择器,第1张

概述我的选择器是:<itemandroid:state_pressed="true"android:color="@color/bg_grey"/><itemandroid:state_focused="true"android:color="@color/bg_grey"/><itemandroid:color="@color/white"/>我的Tex

我的选择器是:

<item androID:state_pressed="true" androID:color="@color/bg_grey"/><item androID:state_focused="true" androID:color="@color/bg_grey"/><item androID:color="@color/white"/>

我的TextVIEw为:

    <TextVIEw        androID:ID="@+ID/tv"        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:gravity="center"        androID:background="@drawable/textvIEw_selector"        androID:padding="5dp"        androID:text="Some Text"        androID:textcolor="@color/text_grey"        androID:textSize="16dp" />

这样我得到:

androID.vIEw.InflateException: Binary xml file line #68: Error inflating class <unkNown>

如果我使用这个选择器作为androID:textcolor =“@ drawable / textvIEw_selector”它的工作正常

解决方法:

这里的问题是你不能使用颜色选择器定义背景颜色,你需要一个可绘制的选择器.因此,必要的更改将如下所示:

<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID">    <item        androID:state_pressed="true"        androID:drawable="@drawable/selected_state" /></selector>

您还需要将该资源移动到drawable目录,在那里它会更有意义,因为它本身不是颜色选择器.

然后你必须像这样创建res / drawable / selected_state.xml文件:

<?xml version="1.0" enCoding="UTF-8"?><shape xmlns:androID="http://schemas.androID.com/apk/res/androID"     androID:shape="rectangle">    <solID androID:color="@color/bg_grey" /></shape>

最后,你会像这样使用它:

androID:background="@drawable/selector"
总结

以上是内存溢出为你收集整理的Android:为什么我无法使用TextView背景的选择器全部内容,希望文章能够帮你解决Android:为什么我无法使用TextView背景的选择器所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1115996.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存