我只想知道,我们可以改变特定数组索引的颜色吗?我有一个下面的数组:
String [] all={"1","2","3","4","5","6","7","8","9","10"};因此,我希望通过ArrayAdapter将数字6打印为红色,其余为黑色。
如何更改数组索引的颜色?请帮帮我!
发布于 2014-02-06 15:22:05
对于文本颜色,在可绘制文件夹中创建以下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>现在创建一个仅包含文本视图的布局:
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"
/>在代码中:
new ArrayAdapter<String>(this, R.layout.item_layout);现在,如果您希望第6项具有不同的文本颜色调用
mylistview.setChoiceMode(1);
mylistview.setItemChecked(6, true);发布于 2014-02-06 15:21:40
是的,你可以简单地做到这一点……
for (int i = 0; i < all.length; i++) {
if(i<=6){
Textview.setTextColor(Color.RED);
}else{
Textview.setTextColor(Color.BLACK);
}
}如果你需要任何帮助,请告诉我!!
https://stackoverflow.com/questions/21596377
复制相似问题