Cambiar el color del texto
Tengo un fondo blanco pero con esta disposición estoy bloqueado porque el color de texto es blanco también y no puedo encontrar una solución para hacerlo rojo así que puedo fijar mi fondo blanco, cualquier ayuda por favor (como u puede ver que soy forzado a Utilizar un fondo rojo para que pueda ver el texto blanco).
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); } }
- Anidado RelativeLayouts dentro de LinearLayout
- TextView Top Padding problema?
- Cómo cambiar el texto en datepicker?
- Dos TextViews lado a lado, sólo uno para ellipsizar?
- ¿Cómo referenciar un control de otro durante la inflación?
- Tablayout de la biblioteca de soporte de diseño de Android mediante el diseño de pestañas personalizadas, pero el diseño que envuelve las pestañas
- Cómo manejar enlaces de texto HTML en la actividad actual
- Disposición de Android con 2 botones espaciados uniformemente
- Android: LinearLayout con match_parent no coincide con Parent
- Android: RecyclerView dentro de un ScrollView (o paralaje)
- Agregar vista a disposición relativa detrás de una vista existente provoca parpadeo de la pantalla
- Android - diseño de xml como fondo
- Cómo agregar múltiples TextView dynamicall a la definición LinearLayout en main.xml
El mejor truco es copiar el archivo de diseño de contenido de android.R.layout.simple_list_item_multiple_choice
y hacer su propio diseño (my_list_view y editar el archivo xml y cambiar el color del texto.
Adapter = new ArrayAdapter (this, my_list_view, listItems);
Editar guardar este archivo como 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 />
android:textColor="@android:color/white"
Puede configurarlo en el diseño XML:
<TextView ... ... android:textColor="#FF0000" > </TextView>
O programáticamente:
textview.setTextColor(Color.RED); //textview must be defined in your class
Mejor escribir adpter personalizado.
Suplente pero no bueno soltuon es usar este layout xml inspace de 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 />
Esta es la misma distribución de android.R.layout.simple_list_item_multiple_choice pero ahora estás haciendo lo mismo en tus diseños con ids idénticos para realizar los cambios en él.
Usted puede intentar la opinión de la lista de encargo. Siga el acoplamiento chasque aquí
<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" />