Can you elaborate on what kind of styling you are seeking to apply?
If it's just basic text styling, you could probably build a Spannable
and set the completion hint with the result, since it accepts a CharSequence
. An example of building a Spannable
and apply styles to it is illustrated in this post.
If you're looking for a way to actually manipulate the parameters of the TextView
(e.g. padding), the source code of AutoCompleteTextView
seems to provide a hint (pun intended).
private View getHintView(Context context) {
if (mHintText != null && mHintText.length() > 0) {
final TextView hintView = (TextView) LayoutInflater.from(context).inflate(
mHintResource, null).findViewById(com.android.internal.R.id.text1);
hintView.setText(mHintText);
hintView.setId(HINT_VIEW_ID);
return hintView;
} else {
return null;
}
}
This reveals that Android looks for the id text1
in the resource reference you specify. The most basic version of such a resource would contain nothing but a TextView
with this id:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:padding="10dp"
android:textColor="#FF0000" android:textSize="16sp" />
Save above in a layout file (e.g. completion_hint_view.xml
) and reference it as follows from your AutoCompleteTextView
:
<AutoCompleteTextView android:id="@+id/autocomplete_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionHintView="@layout/completion_hint_view"/>
This second option is probably the easiest to use and will give you full access to the TextView's parameters. If you need to apply multiple styles to the text in this view, you can incorporate the first suggestion, as that will give you more flexibility.
If neither of these suggestions suffice, I can think of some less elegant work arounds that would probably allow you to get the same result.