How to change the color of an array element in android? -
i want know , can change color of particular array index? have following array-:
string [] all={"1","2","3","4","5","6","7","8","9","10"};
so , want print number 6 in red color , rest in black through arrayadapter.
how can change color of array index? please me out !!!
for text color create following xml in drawable folder:
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>
now create layout textview only:
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);
now if want 6th item have different text color call
mylistview.setchoicemode(1); mylistview.setitemchecked(6, true);
Comments
Post a Comment