2

默认情况下,当您在微调器中选择一个项目时,它会在消失之前短暂突出显示。

我使用以下代码将微调器行的颜色更改为交替颜色,然后突出显示消失。R.layout.textviewinside 和 R.layout.textview 不会导致这种情况,只是 getDropDownView 的 @Override,因为如果我注释掉该块,一切都会正常工作。

如何恢复该功能但保留行颜色?

products = new ArrayAdapter<String>(this,   R.layout.textview, thedata){
                @Override
                public View getDropDownView(int position, View convertView, ViewGroup parent) {
                    View v = super.getDropDownView(position, convertView, parent);
                    if (position % 2 == 0) { // we're on an even row
                        v.setBackgroundColor(0xffEBF4FA);//Color.BLUE)
                    } else {
                        v.setBackgroundColor(Color.WHITE);
                    }
                    ((TextView) v).setGravity(Gravity.CENTER);

                    return v;
                }
            };
            products.setDropDownViewResource(R.layout.textviewinside);

            spitem.setAdapter(products);
4

1 回答 1

1

您需要使用 setBackgroundDrawable,而不是使用 setBackgroundColor,并使用具有按下/默认状态的 xml 状态列表可绘制文件。

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

于 2013-07-08T16:21:02.907 回答