安卓 Spinner 文字颜色
可以通过设置 Spinner 的 Adapter 中的 TextView 的颜色来改变 Spinner 文字颜色。
可以在自定义的 SpinnerAdapter 的 getView() 方法中设置 TextView 的颜色,例如:
public class MySpinnerAdapter extends ArrayAdapter<String> {
private Context mContext;
private ArrayList<String> mData;
public MySpinnerAdapter(Context context, ArrayList<String> data) {
super(context, android.R.layout.simple_spinner_item, data);
mContext = context;
mData = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) super.getView(position, convertView, parent);
textView.setTextColor(mContext.getResources().getColor(R.color.spinner_text_color));
return textView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) super.getDropDownView(position, convertView, parent);
textView.setTextColor(mContext.getResources().getColor(R.color.spinner_text_color));
return textView;
}
}
在这个例子中,我们自定义了一个 SpinnerAdapter,重写了 getView() 和 getDropDownView() 方法,在这两个方法中设置了 TextView 的颜色为 R.color.spinner_text_color。可以根据需要修改颜色值
原文地址: https://www.cveoy.top/t/topic/e2P0 著作权归作者所有。请勿转载和采集!