我想知道如果可以,請在選擇時自定義AutoCompleteTextView
下拉列表的顏色。我可以自定義一切,但不是所選的顏色,即 - 它保持不變。如何在Android上自定義AutoCompleteTextView下拉菜單
在Activity
:
ArrayAdapter<String> adap = new ArrayAdapter<String>(this, R.layout.row, strings);
autoNewBird = (AutoCompleteTextView)findViewById(R.id.autoCompleteBirdName);
autoNewBird.setAdapter(adap);
row.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/birdtext"
android:padding="5dip"
android:background="@drawable/custom_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/spinner_item"
android:gravity="center_vertical"
android:layout_gravity="center_vertical" android:lines="1"/>
和繪製custom_spinner.xml(在繪製文件夾)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/listback" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="@drawable/listback" />
<item android:state_pressed="true" android:drawable="@drawable/threebythree" />
<item android:state_enabled="true" android:state_focused="true"
android:drawable="@drawable/threebythree" />
<item android:state_enabled="true" android:drawable="@drawable/listback" />
<item android:state_focused="true" android:drawable="@drawable/listback" />
<item android:drawable="@drawable/listback" />
</selector>
這適用於一個微調下拉,但對於AutoCompleteTextView
,選中後,它不會像更改顏色一樣微調下拉。
任何幫助,或經驗與此將不勝感激。
這是正確的解決方案。爲了進一步說明,第二行應該像這樣定義樣式:。希望有幫助:) – Sandra 2013-06-25 09:22:13
你使用哪種佈局來佈局?我這樣做aAdapterAutoComplete = new ArrayAdapter(getActivity()。getApplicationContext(),R.layout.auto_complete_text,suggest); \t \t \t \t \t autoComplete.setAdapter(aAdapterAutoComplete); –
user1163234
2014-04-28 14:58:47