How to set dropdown arrow in spinner?

前端 未结 10 781
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 14:40

I tried to set spinner with drop down arrow but i couldn\'t fix it can anyone help me with this? I have attached the source code.

my class file:

             


        
10条回答
  •  自闭症患者
    2020-11-27 15:11

    From the API level 16 and above, you can use following code to change the drop down icon in spinner. just goto onItemSelected in setonItemSelectedListener and change the drawable of textview selected like this.

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView parent, View view, int position, long id) {
      // give the color which ever you want to give to spinner item in this line of code               
    //API Level 16 and above only. 
               ((TextView)parent.getChildAt(position)).setCompoundDrawablesRelativeWithIntrinsicBounds(null,null,ContextCompat.getDrawable(Activity.this,R.drawable.icon),null);
     //Basically itis changing the drawable of textview, we have change the textview left drawable.
    
    }
            @Override
            public void onNothingSelected(AdapterView parent) {
    
    }
        });
    

    hope it will help somebody.

提交回复
热议问题