Cómo cambiar el color de texto de la lista desplegable en un AutoCompleteTextView?

¿Cómo puedo cambiar el color del texto en el menú desplegable de un AutoCompleteTextView ? O cómo puedo cambiar el color de fondo de un menú desplegable, por defecto el color de fondo del desplegable es blanco.

Usted necesita crear la clase del adaptador de encargo para esto, después usted puede fijar el textview a esto tiene gusto.

 autoAdapter = new AutoAdapter(this, R.layout.autocompletelistview_test1, edittext); 

Aquí está autocompletelistview_test1

 <?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="44dip" android:gravity="center_vertical" android:singleLine="true" android:ellipsize="end" android:layout_marginRight="12dip" android:textStyle="bold" android:textColor="#cc3333" android:id="@+id/textview" android:textSize="14sp" /> 

Utilice el siguiente código para cambiar el color de fondo del menú desplegable como

  autocomplete.setDropDownBackgroundResource(R.color.autocompletet_background_color); 

Y usted puede fijar el valor como esto en string.xml

  <color name="autocompletet_background_color">#EFEFEF</color> 

Si desea cambiar el color de texto del elemento desplegable, haga lo siguiente.

En la clase Adaptador.

  @Override public View getView(int position, View v, ViewGroup parent) { View mView = v ; if(mView == null){ LayoutInflater vi = (LayoutInflater)appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mView = vi.inflate(id, null); } TextView text = (TextView) mView.findViewById(R.id.textview); if(getItem(position) != null ) { text.setTypeface(faceBold); if(getItem(position).equals("check some condition if you want. ")) { text.setTextColor(Color.parseColor("#999999")); text.setText("set some text"); } else { text.setTextColor(Color.parseColor("#cc3333")); text.setText(getItem(position)); } } return mView; } 

Déjeme saber si usted tiene cualquier pregunta.

Aunque puede ser difícil cambiar el color del texto. Es fácil cambiar el color de fondo del menú desplegable

 AutoCompleteTextView searchView = ... searchView.setDropDownBackgroundDrawable(new ColorDrawable(context.getResources().getColor(R.color.colorId))); 

En realidad, no es posible cambiar directamente el color del auto-complete textView de forma predeterminada. En su lugar, tiene que implementar el adaptador personalizado para tal e inflar la vista desde el adaptador normalmente textView. Vea esta pregunta que le ayudará a resolver su problema. Así que puede establecer las propiedades de la vista de texto como desee .. Por ejemplo, debe tener el adaptador personalizado como a continuación

 public class MyCustomBrandAdapter extends ArrayAdapter<Brand>{ List<Brand> Brandlist; Context context; private ArrayList<Brand> itemsAll; private ArrayList<Brand> suggestions; public MyCustomBrandAdapter(Context context, int textViewResourceId, List<Brand> Brandlist) { super(context, textViewResourceId, Brandlist); this.Brandlist = Brandlist; this.itemsAll = (ArrayList<Brand>) ((ArrayList<Brand>) Brandlist).clone(); this.suggestions = new ArrayList<Brand>(); this.context = context; } public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.listview, null); } Brand Brand = Brandlist.get(position); if (Brand != null) { TextView tt = (TextView) v.findViewById(R.id.txtName); if (tt != null) { tt.setText(Brandlist.get(position).toString()); } else { System.out.println("Not getting textview.."); } } return v; } @Override public Filter getFilter() { return nameFilter; } Filter nameFilter = new Filter() { public String convertResultToString(Object resultValue) { String str = ((Brand)(resultValue)).getBrandDescription1(); return str; } @Override protected FilterResults performFiltering(CharSequence constraint) { if(constraint != null) { suggestions.clear(); for (Brand brand : itemsAll) { if(brand.getBrandDescription1().toLowerCase().startsWith(constraint.toString().toLowerCase())){ suggestions.add(brand); } } FilterResults filterResults = new FilterResults(); filterResults.values = suggestions; filterResults.count = suggestions.size(); return filterResults; } else { return new FilterResults(); } } @Override protected void publishResults(CharSequence constraint, FilterResults results) { ArrayList<Brand> filteredList = (ArrayList<Brand>) results.values; List<Brand> getResult=new ArrayList<Brand>(); if(results != null && results.count > 0) { clear(); for (Brand c : filteredList) { getResult.add(c); } Iterator<Brand> brandIterator=getResult.iterator(); while(brandIterator.hasNext()){ Brand party=brandIterator.next(); add(party); } notifyDataSetChanged(); } } }; } 

Y en esto el layout R.layout.listview xml es el siguiente

  <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="#ffffff" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/txtName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:textColor="#000000" android:textSize="12dp"/> </LinearLayout> </LinearLayout> 

Aquí en este xml. He definido el fondo como blanco (android:background="#ffffff") y quiero texto como negro (android:textColor="#000000") y el tamaño como (android:textSize="12dp") como quiero modificarlo. Creo que ahora obtendrá u claramente.

  • Sugerencia de float de AutoCompleteTextView
  • Los elementos de la caja desplegable de autocompletetextview de Android tienen una fuente grande
  • Android: Autocompletar TextView similar a la aplicación de Facebook
  • Mostrar todos los elementos de AutocompleteTextView sin escribir texto
  • Los espacios no funcionan cuando se utiliza la API de autocompletar de Google Places
  • AutoCompleteTextView recorta la última fila
  • Android AutoCompleteTextView sugiere alternativa
  • Cómo filtrar los resultados de AutoCompleteTextView?
  • Android AutoCompleteTextView muestra información de objeto en lugar de texto en modo horizontal
  • Cambiar filtro AutoCompleteTextView de "startsWith" a "Contains"?
  • Cómo mantener DropDownList de AutoCompleteTextView abierto después de presionar la tecla Atrás?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.