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

后端 未结 3 1944
迷失自我
迷失自我 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:42

    I Think that xml style was changed

    http://developer.android.com/design/building-blocks/spinners.html

    0 讨论(0)
  • 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!

    0 讨论(0)
  • 2020-12-18 06:51

    I have the same problem. The only workaround I found is combining the selector icon to the background and then override the background only. Don't use the android:spinnerSelector attribute.

    0 讨论(0)
提交回复
热议问题