0

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.androidenter image description here

Daniel
  • 1,537
  • 1
  • 13
  • 16
Niteesh Kumar
  • 213
  • 3
  • 18
  • Try to use custom adapter instead of ArrayAdapter where you can override GetView method like in Java – Dmitriy Kaluzhin Jul 01 '18 at 15:25
  • @Dmitriy Kaluzhin, Thanks for response. I know custom adapter, i need to know in this way, can u help? – Niteesh Kumar Jul 01 '18 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 01 '18 at 16:40
  • you can try this one: https://stackoverflow.com/questions/4533440/android-listview-text-color – MShah Jul 02 '18 at 04:34

1 Answers1

0

I had that same situation and was able to fix it setting a new "item" entry on the styles.xml file:

<item name="android:textColorPrimary">@color/colorAccent</item>

The color value can be any entry reference to your colors.xml or an hexadecimal value

Neto
  • 1