我有一个基本的AutoCompleteTextView和一个绑定到它的ArrayAdapter.在 Android 4. *上工作得很好,但是在2.3滚动下拉列表时,行会全部呈现黑色.如果我点击一行,则整个下拉列表正确呈现. 在下面的文
在下面的文本中,当使用inflate生成TextView时,如果我将背景颜色设置为白色(注释掉的行),那么即使滚动也总是显示白色,但是点击选择效果(将行更改为系统点击a)行颜色)然后不起作用.
我在这里使用actionbarsherlock,但我希望这不是原因.有任何想法吗?
截图:http://i.imgur.com/gnugp.png
public class AutocompleteAdapter extends ArrayAdapter<String> implements Filterable {
public AutocompleteAdapter(Context context) {
super(context, android.R.layout.simple_dropdown_item_1line);
mInflater = LayoutInflater.from(context);
mContext = context;
}
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
final TextView tv;
if (convertView != null) {
tv = (TextView) convertView;
} else {
tv = (TextView) mInflater.inflate(android.R.layout.simple_dropdown_item_1line, parent, false);
//tv.setBackgroundColor(tv.getResources().getColor(R.color.white));
}
tv.setText(getItem(position));
return tv;
}
....
因为你的主题很暗..
如果您在Manifest.xml中的主题很轻..即,
<application
android:label="@string/app_name"
android:theme="@style/Theme.Light.NoTitleBar.Workaround" >
我通过在values文件夹中添加2个xml文件来实现它.
styles.xml
<resources>
<style name="AppTheme" parent="android:Theme.Light" />
<style name="AutoCompleteTextViewLight" parent="@android:style/Widget.AutoCompleteTextView">
<item name="android:textColor">@android:color/primary_text_light</item>
</style>
<style name="Widget.DropDownItemLight" parent="@android:style/Widget.DropDownItem">
<item name="android:textColor">@android:color/primary_text_light</item>
</style>
</resources>
theme.xml
<resources>
<style name="Theme.Light.NoTitleBar.Workaround" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewLight</item>
<item name="android:dropDownItemStyle">@style/Widget.DropDownItemLight</item>
</style>
</resources>
我找不到另一种方式……
