How to change spinner text size and text color?

后端 未结 24 1777
囚心锁ツ
囚心锁ツ 2020-11-22 11:35

In my Android application, I am using spinner, and I have loaded data from the SQLite database into the spinner, and it\'s working properly. Here is the code for that.

24条回答
  •  无人及你
    2020-11-22 12:19

    I have done this as following.I have use getDropDownView() and getView() methods.

    Use getDropDownView() for opened Spinner.

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
      View view = convertView;
      if (view == null) {
        LayoutInflater vi = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = vi.inflate(R.layout.context_row_icon, null);
      }
      TextView mTitle = (TextView) view.findViewById(R.id.context_label);
      ImageView flag = (ImageView) view.findViewById(R.id.context_icon);                
    
      mTitle.setText(values[position].getLabel(activity));
    
      if (!((LabelItem) getItem(position)).isEnabled()) {
        mTitle.setTextColor(activity.getResources().getColor(R.color.context_item_disabled));
      } else {
        mTitle.setTextColor(activity.getResources().getColor(R.color.context_item));
      }
      return view;
    }
    

    And Use getView() for closed Spinner.

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View view = convertView;
      if (view == null) {
        LayoutInflater vi = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = vi.inflate(R.layout.context_row_icon, null);
      }
      TextView mTitle = (TextView) view.findViewById(R.id.context_label);
      ImageView flag = (ImageView) view.findViewById(R.id.context_icon);
    
      mTitle.setText(values[position].getLabel(activity));
      mTitle.setTextColor(activity.getResources().getColor(R.color.context_item_disabled));
    
      return view;
    }
    

提交回复
热议问题