How to change ListView item text color in Xamarin.Android?

Multi tool use
How to change ListView item text color in Xamarin.Android?
I have a simple ListView like below : -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/asimplelistView1"
/>
I am binding this ListView by array ArrayAdapter using:
ArrayAdapter<string> arrayAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleExpandableListItem1,mItems);
My app secondary text color is white(#FFFFFF) and theme is android:Theme.Material.Light..
My problem is: I need to change item text color to gray because items text color is not visible on white background.
In Java we can do like below:
// Create a List from String Array elements
List<String> fruits_list = new ArrayList<String>(Arrays.asList(fruits));
// Create an ArrayAdapter from List
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
(this, android.R.layout.simple_list_item_1, fruits_list){
@Override
public View getView(int position, View convertView, ViewGroup parent){
// Get the Item from ListView
View view = super.getView(position, convertView, parent);
// Initialize a TextView for ListView each Item
TextView tv = (TextView) view.findViewById(android.R.id.text1);
// Set the text color of TextView (ListView Item)
tv.setTextColor(Color.RED);
// Generate ListView Item using TextView
return view;
}
};
How to achieve this in C# using xamarin.android
@Dmitriy Kaluzhin, Thanks for response. I know custom adapter, i need to know in this way, can u help?
– Niteesh Kumar
Jul 1 at 15:30
you can try to send your custom view in ArrayAdapter constructor instead of SimpleExpandableListItem1 or create another adapter inherited ArrayAdapter class where you can override GetView method
– Dmitriy Kaluzhin
Jul 1 at 16:40
you can try this one: stackoverflow.com/questions/4533440/android-listview-text-color
– MShah
Jul 2 at 4:34
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Try to use custom adapter instead of ArrayAdapter where you can override GetView method like in Java
– Dmitriy Kaluzhin
Jul 1 at 15:25