Search code examples
androidkotlinmaterial-designandroid-viewautocompletetextview

programatically hide drown down arrow in autocomeplete textView


I am trying to create a EditText that usually acts as a normal text input field, but under particualar situations acts as an autocomplete textfield with exposed drowndown.

So far i have tried replacing the end drawable with an invisible drawable, which only hid the button, but did not change its behaviour, have added negative padding, which hid the button, but it was still clickable from outside the view, and also made the view ugly. I also thought about switching the style programatically, but learned this could not be done, and creating 2 views I swap between in a frame layout, but would rather avoid this.

The views im using are a AutoCompleteTextView, wrapped in a TextInputLayout from the material design support libary, if there anyway i can achive the effect I want?


Solution

  • So from what I understood, the problem is removing the dropdown icon.

    say I have TextInputLayout view 'text_input_layout' and the child autoCompleteTextView as 'auto_complete_text_view'

    so the answer should look like this.

    \\you might need to import END_ICON_NONE specifically if not done automatically.
    import com.google.android.material.textfield.TextInputLayout.END_ICON_NONE
    
    \\Text input layout
    val textLayout :TextInputLayout = view.findViewById(R.id.text_input_layout)
    
    \\ no need to get autoCompleteTextView
    
    \\simply use endIconMode
    textLayout.endIconMode = END_ICON_NONE
    
    \\you can also use
    textLayout.setEndIconMode(END_ICON_MODE)
    

    Hope this helps you out, let me know if you have any further questions.