【发布时间】:2012-07-05 08:56:09
【问题描述】:
ImageSpan中可以使用selectordrawable吗?
我有带有选择器文本颜色的TextView,并添加了带有选择器资源的 ImageSpan。文本颜色更改工作正常,图像不会更改。这是一个错误还是有办法使选择器跨度?
我的TextView:
<TextView
android:id="@+id/text"
android:ellipsize="end"
android:layout_height="fill_parent"
android:duplicateParentState="true" // parent of this text view can be selected
android:gravity="center_vertical"
android:lines="1"
android:textColor="@color/message_content_simple_text" // here is selector - it works fine
android:textSize="15dp" />
选择器:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_active" android:state_focused="true"/>
<item android:drawable="@drawable/ic_active" android:state_selected="true"/>
<item android:drawable="@drawable/ic_active" android:state_pressed="true"/>
<item android:drawable="@drawable/ic_passive"/>
</selector>
以及添加span的代码:
SpannableString text = new SpannableString(" some text");
ImageSpan span = new ImageSpan(context, R.drawable.icon, ImageSpan.ALIGN_BASELINE);
text.setSpan(span, 0, 1, SpannableString.SPAN_INCLUSIVE_INCLUSIVE);
textView.setText(text);
当我选择这个文本视图时,“一些文本”会根据需要改变它的颜色,但图像不会改变。
编辑
如果有一些android bug,你能提供任何方法来达到同样的结果吗?
【问题讨论】:
-
@imran khan 我已经发布了我的代码
-
stackoverflow.com/questions/16582806/…我有一个关于 ImageSpan 的问题,你能帮我吗?
标签: android