浩晨众云网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
android原生的下拉框Spinner基本上可以满足Android开发对于下拉选项的设计需求,但现在越来越流行的下拉框不满足于Android原生提供的下拉框Spinner所提供的设计样式,而改用自定制或者第三方设计的下拉框Spinner。
NiceSpinner是一个第三方开源的下拉框Spinner,其在github上的项目主页是:https://github.com/arcadefire/nice-spinner
NiceSpinner原设计效果如动图所示:
但是通常开发者对于可能还需要对于下拉框中出现的文字和样式进行二次开发,比如如果希望NiceSpinner的选中文本颜色或者下拉弹出框中的文字有些变化,则需要重新二次定制NiceSpinner code项目中的NiceSpinnerBaseAdapter, NiceSpinnerBaseAdapter中的getView返回的view表现形式即为下拉框中的结果:
//这个方法将返回下拉列表的形制,可以在这里修改和二次定制开发。 //zhang phil 注解 @Override @SuppressWarnings("unchecked") public View getView(int position, View convertView, ViewGroup parent) { TextView textView; if (convertView == null) { convertView = View.inflate(mContext, R.layout.spinner_list_item, null); textView = (TextView) convertView.findViewById(R.id.tv_tinted_spinner); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { textView.setBackground(ContextCompat.getDrawable(mContext, mBackgroundSelector)); } convertView.setTag(new ViewHolder(textView)); } else { textView = ((ViewHolder) convertView.getTag()).textView; } textView.setText(getItem(position).toString()); textView.setTextColor(mTextColor); //这里是被zhang phil修改的,用于改变下拉列表的文字颜色。 textView.setTextColor(Color.RED); return convertView; }