Android – How to change the border and separator color of spinner widget

android

I have customised the spinner items background into black color.But border around spinner and the separartor between each spinner item is in white color.
I want to change separator color and border to dark gray color.

  • How can i change these color?
  • Is spinner uses list view or some other as parent to populate items in spinner?
  • If so can i change the separator background of parent view?

Best Solution

First, you have to define view (horizontal line) which is the separator line of items of spinner and you can change that separator line color at runtime using spinner's setOnItemSelectedListener method like this:

View tview1 = (View) view.findViewById(R.id.v_1 );
tview1.setBackgroundResource(android.R.color.transparent);

For example, XML file:

<Spinner
    android:id="@+id/move_branch"
    android:backgroundTint="@color/color"
    android:layout_width="0dp"
    style="@style/Base.Widget.AppCompat.Spinner.Underlined"
    android:layout_weight="1"
    android:layout_height="wrap_content" />

MainActivity.java:

Spinner move_sem;    // define spinner's id first

move_sem.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
    {
        View tview1 = (View) view.findViewById(R.id.v_1 );
        tview1.setBackgroundResource(android.R.color.transparent);
        try
        {
            search_sem= Integer.parseInt(semid.get(position) );
            semname=sem_list.get(position);
        }
        catch (Exception ignored)
        {
        }
    }
    @Override
    public void onNothingSelected(AdapterView<?> parent)
    {
    }
});