Home » Android » android – AutoCompleteTextView problem on lost focus

android – AutoCompleteTextView problem on lost focus

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have a AutoCompleteTextView within my activity that performs how it should. The dropdown bow is shown with correct entries etc. The problem is when the view looses focus the text is no longer visible. When focus is gained again the text is visible.

Has anyone else had this problem? Is it a bug or something I am doing wrong?

How to&Answers:

Maybe when you don’t focus the Item,TextColor is same as background color on current Theme .so you can’t see them,just see the item text that you focus.

Solve : set different color against background_color.
you can use android.R.layout.simple_dropdown_item_1line and so on when you create Adapter ,or your own textViewResourceId like:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
   android:textSize="20dp"
   android:gravity="center_vertical" 
   android:id="@android:id/text1" 
   android:paddingLeft="6.0dip" 
   android:paddingRight="6.0dip" 
   android:layout_width="fill_parent" 
   android:layout_height="50.0dip"
   android:textColor="@android:color/black"
   android:textColorHighlight="@android:color/black"    />

Answer:

It’s as easy as set textcolor of textview,

 <AutoCompleteTextView
         android:layout_width="120dip"
         android:layout_height="wrap_content"
         android:singleLine="true"
         android:ems="10"
         android:textColor="@android:color/black" />