我有一个基本的 AutoCompleteTextView
和一个绑定(bind)到它的 ArrayAdapter
。在 Android 4.* 上运行良好,但在 2.3 上,每当我滚动下拉列表时,行呈现全黑。如果我点击一行,则整个下拉菜单会正确呈现。
在下面的文本中,当使用 inflate
生成 TextView 时,如果我将背景颜色设置为白色(注释掉的行),那么即使在滚动时它也总是显示白色,但是点击选择效果(将行更改为系统点击行颜色)则不起作用。
我在这里使用 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 中的主题是 light.. ie,
<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>
主题.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>
我找不到其他方法...
关于android - AutoCompleteTextView - 下拉行在 Android 2.3 中滚动时变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14251606/