Android: How to set spinner selector to own image/icon?

后端 未结 3 1954
迷失自我
迷失自我 2020-12-18 06:14

I have searching and testing to set my own image/icon in a Spinner but i get error.

I have alrady with styling set background image but then the spinner icon on the

3条回答
  •  清酒与你
    2020-12-18 06:49

    I didn't get the answer for changing the spinner image but you can do it..

    1. Set the spinner height and width to 0dp

    2. Create a button in the onClick() listener and call click action of the spinner like this

      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              spin.performClick();
          }
      });
      
    3. Change the button text to match the spinner text.

      public void onItemSelected(AdapterView parent, View v, int position, long id) {
          button.setText(items[position]);
      }
      
    4. Now you can change the image of the button easily!

提交回复
热议问题