我只是想知道,我们可以更改特定数组索引的颜色吗?我有一个以下数组-:
String [] all={"1","2","3","4","5","6","7","8","9","10"};
所以,我想通过 ArrayAdapter 以红色打印数字 6,并以黑色打印其余部分。
如何更改数组索引的颜色?请帮帮我!
对于文本颜色,在可绘制文件夹中创建以下 xml:
item_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:color="#777"/>
<item android:state_focused="true" android:color="#000"/>
<item android:color="#000"/>
</selector>
现在创建一个仅包含 textview 的布局:
item_layout.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="@drawable/item_bg"
/>
in code:
new ArrayAdapter<String>(this, R.layout.item_layout);
现在,如果您希望第 6 个项目具有不同的文本颜色,请致电
mylistview.setChoiceMode(1);
mylistview.setItemChecked(6, true);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)