Tôi muốn biết cách thực hiện, nếu có thể, để tùy chỉnh màu của menu thả xuống từ AutoCompleteTextView
khi được chọn. Tôi có thể tùy chỉnh mọi thứ khác, nhưng không phải là màu đã chọn - nó vẫn giữ nguyên.Cách tùy chỉnh menu thả xuống AutoCompleteTextView trên Android
Trong 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"/>
và custom_spinner.xml drawable (trong thư mục drawable)
<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>
này làm việc cho một thả xuống spinner , nhưng đối với một số AutoCompleteTextView
, khi được chọn, nó sẽ không thay đổi màu sắc như trình đơn thả xuống.
Mọi trợ giúp hoặc trải nghiệm với điều này sẽ được đánh giá cao.
Đây là giải pháp đúng. Để biết rõ hơn, dòng thứ hai phải được định kiểu như sau: . Hy vọng rằng sẽ giúp :) – Sandra
Bố cục nào bạn đang sử dụng cho bố cục? Tôi đang làm như thế này aAdapterAutoComplete = new ArrayAdapter (getActivity(). GetApplicationContext(), R.layout.auto_complete_text, gợi ý); \t \t \t \t \t autoComplete.setAdapter (aAdapterAutoComplete); –
user1163234