gpt4 book ai didi

Android Spinner 文本颜色

转载 作者:太空宇宙 更新时间:2023-11-03 12:11:12 36 4
gpt4 key购买 nike

我有一个 Spinner,为了填充他,我使用了 SimpleCursorAdapter。我希望微调器的字体颜色为黑色,下拉菜单的字体颜色为白色。我有这段代码:

String[] column = { "name" };
int[] viewIds = new int[] { R.id.spinner_dropdown_design_from };

SimpleCursorAdapter fromListAdapter = new SimpleCursorAdapter(MyClass.this, R.layout.spinner_drop_down_from, cursor,
column, viewIds) {

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View viewFromListAdapter = super.getDropDownView(position, convertView, parent);
if (position % 2 == 0) {
viewFromListAdapter.setBackgroundResource(R.layout.dropdown_selector_odd);
} else {
viewFromListAdapter.setBackgroundResource(R.layout.dropdown_selector_even);
}
return viewFromListAdapter;
}

};

所以我在下拉列表中对奇数行和偶数行使用不同的布局。我给你一个 dropdown_selector_even 的例子

 <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/grey_background"/>
<item android:state_focused="true" android:drawable="@drawable/blue_background"/>
<item android:state_pressed="true" android:drawable="@drawable/blue_background"/>
<item android:drawable="@drawable/grey_background"/>
</selector>

和 spinner_drop_down_from

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner_dropdown_design_from"
android:layout_height="100dip"
android:layout_width="fill_parent"
android:paddingLeft="20dip"
android:textSize="40dip"
android:gravity="center_vertical"
android:textStyle="normal|bold"
android:textColor="#000000"/>

有人可以帮助我吗?提前致谢!

最佳答案

我找到了解决方案。我还必须覆盖 getView 方法像这样

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text = (TextView) view.findViewById(R.id.spinner_dropdown_design_products);
text.setTextColor(Color.WHITE);
return view;
}

关于Android Spinner 文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9808413/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com