MaterialAutoCompleteTextView selected item text color

38 Views Asked by At

I need to change my spinner's selected item text color. I use Material's AutoCompleteTextView. it has an attribute (app:simpleItemSelectedColor) but it only changes the background color. I need to change the text color

This is my spinner:

<com.google.android.material.textfield.MaterialAutoCompleteTextView
            android:id="@+id/lang_spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:dropDownVerticalOffset="@dimen/_4sdp"
            android:inputType="none"
            android:popupBackground="@drawable/custom_popup_background"
            android:popupElevation="0dp"
            app:simpleItemSelectedColor="@color/red"
            android:textColor="@android:color/transparent"
            android:textSize="@dimen/_2sdp"
            app:simpleItemLayout="@layout/custom_spinner_textview"
            app:simpleItems="@array/languages" />

I tried to access the textView inside the spinner to change the color but couldn't access it:


        spinner.onItemClickListener = OnItemClickListener { parent, view, position, id ->
            val selectedItem1 = parent?.getItemAtPosition(position) as TextView
            val selectedItem2 = parent.adapter?.getItem(position) as TextView
            val textView = view as MaterialTextView


        spinner.onItemSelectedListener = object: OnItemSelectedListener{
            override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
            val selectedItem1 = p0?.getItemAtPosition(position) as TextView
            val selectedItem2 = p0.adapter?.getItem(position) as TextView
            val textView = p1 as MaterialTextView

            }

            override fun onNothingSelected(p0: AdapterView<*>?) {
            }
        }

    //These didn't work

0

There are 0 best solutions below