Change text color

I have a white background, but with this arrangement I’m locked because the text color is white too and I can’t find a solution to make it red so that I can set my white background, any help please (since you can see I I am forced to use a red background so that I can see the white text).

public class QueueListActivity extends ListActivity { // LIST OF ARRAY STRINGS WHICH WILL SERVE AS LIST ITEMS ArrayList<String> listItems = new ArrayList<String>(); String newtext; String listFiles; // DEFINING STRING ADAPTER WHICH WILL HANDLE DATA OF LISTVIEW ArrayAdapter<String> adapter; // RECORDING HOW MUCH TIMES BUTTON WAS CLICKED int clickCounter = 0; ArrayList<String> selectedItems = new ArrayList<String>(); @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.queuelistactivity); Bundle extras1 = getIntent().getExtras(); listFiles=GetFiles(); StringTokenizer tokonizer1 = new StringTokenizer(listFiles,";"); while(tokonizer1.hasMoreElements()){ Log.i("verif","0"); listItems.add(tokonizer1.nextToken());} initializeListItems(); if (extras1 != null) { newtext = extras1.getString("newitem"); listItems.add(newtext); adapter.notifyDataSetChanged(); getListView().setItemChecked(listItems.size() - 1, false); } } // METHOD WHICH WILL HANDLE DYNAMIC INSERTION public void addItems(View v) { Intent intent = new Intent(QueueListActivity.this, AjouterFiles.class); QueueListActivity.this.startActivity(intent); /* listItems.add(userName); adapter.notifyDataSetChanged(); getListView().setItemChecked(listItems.size() - 1, false);*/ } public void deleteItems(View v) { String toDelete = ""; SparseBooleanArray sp = getListView().getCheckedItemPositions(); for (int i = 0; i < sp.size(); i++) { toDelete += ";" + sp.get(i); if (sp.get(i)) { listItems.remove(i); } } adapter.notifyDataSetChanged(); Toast.makeText(getApplicationContext(), toDelete, Toast.LENGTH_LONG).show(); initializeListItems(); } private void initializeListItems() { adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, listItems); setListAdapter(adapter); ListView lv = getListView(); lv.setCacheColorHint(Color.rgb(0, 0, 0)); lv.setBackgroundColor(Color.rgb(178, 34, 34)); for (int i = 0; i < lv.getCount(); i++) { lv.setItemChecked(i, false); } } 
+6
source share
6 answers

The best trick is that you copy the content layout file from android.R.layout.simple_list_item_multiple_choice and create your own layout (my_list_view and edit the xml file and change the color of the text.

adapter = new ArrayAdapter (this, my_list_view, listItems);

Edit save this file as my_list_view;

 <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical" android:checkMark="?android:attr/listChoiceIndicatorMultiple" android:paddingLeft="6dip" android:paddingRight="6dip" android:backdround="#FFFFFF" //white background android:textColor="#000000" //black color text /> 
+11
source
 android:textColor="@android:color/white" 
+4
source

You can set it in an XML layout:

 <TextView ... ... android:textColor="#FF0000" > </TextView> 

Or programmatically:

 textview.setTextColor(Color.RED); //textview must be defined in your class 
+1
source

better to write a custom add-on.

An alternative but not good soltuon uses this xml inspace layout for android.R.layout.simple_list_item_multiple_choice

 <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical" android:checkMark="?android:attr/listChoiceIndicatorMultiple" android:paddingLeft="6dip" android:paddingRight="6dip" android:textColor= Color.Red //please correct the syntax /> 

This is the same android.R.layout.simple_list_item_multiple_choice file, but now you do the same in your layouts with the same identifiers to make changes to it.

0
source

you can try a custom list view .. follow the link click here

0
source
 <TextView android:id="@+id/text_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="Name" android:textColor="@color/white" android:textSize="11dp" /> 
0
source

Source: https://habr.com/ru/post/915977/


All Articles