如何在android中更改下拉视图的标题?

muk*_*esh 5 android android-widget android-layout

我的布局中有一个微调器,并使用android:prompt="@string/year".

默认提示如下所示:

默认提示看起来像

现在我的问题是:

  1. 如何将默认图标更改为其他图像?
  2. 如何让“年份”文本以红色显示在中心?
  3. 如何将背景颜色更改为黄色(存在“年份”文本和图标的背景)?

我的自定义适配器类

private class MyCustomSpinnerAdapter extends ArrayAdapter<ArrayList> {
        private ArrayList<String> objectsList = new ArrayList<String>();

        @SuppressWarnings("unchecked")
        public MyCustomSpinnerAdapter(Context context, int textViewResourceId,
                ArrayList objects) {
            super(context, textViewResourceId, objects);
            this.objectsList = objects;
        }

        @Override
        public View getDropDownView(int position, View convertView,
                ViewGroup parent) {
            return getCustomView(position, convertView, parent);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return getCustomView1(position, convertView, parent);
        }

        public View getCustomView(int position, View convertView,
                ViewGroup parent) {
            LayoutInflater inflater = getLayoutInflater();
            View rowView = inflater.inflate(R.layout.spinner_dropdown, parent,
                    false);
            LinearLayout rowTitle = (LinearLayout) rowView
                    .findViewById(R.id.row);

            rowTitle.setBackgroundResource(R.drawable.spinner_row_focused);

            TextView textView = (TextView) rowView.findViewById(R.id.title);
            textView.setTypeface(typeFace);
            textView.setText(objectsList.get(position).toString().trim());
            return rowView;
        }

        public View getCustomView1(int position, View convertView,
                ViewGroup parent) {
            LayoutInflater inflater = getLayoutInflater();
            View rowView = inflater.inflate(R.layout.spinner_dropdown, parent,
                    false);

            TextView textView = (TextView) rowView.findViewById(R.id.title);
            textView.setText(objectsList.get(position).toString().trim());
            textView.setTypeface(typeFace);
            return rowView;
        }
    }
Run Code Online (Sandbox Code Playgroud)

SuR*_*aTi 1

我认为你最好准备自定义微调器,例如自定义 ListView 并检查此链接http://android-er.blogspot.in/2010/12/custom-spinner-with-icon.html