Query hint remains after user query is entered - overlapping text [Android]

I’m using the InstantSearch Kotlin API. I have a search box where the searchView’s query hint remains visible even after the user begins to type a query. If I set the searchView as “iconifiedByDefault=“true””, then it functions correctly, but that’s not the search view I’m trying to create. Is there an attribute of the searchView I can use to stop this from happening? I have relevant code samples below and a screenshot of what’s occurring.

xml for the fragment:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/group_fragment_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/group_fragment_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar">


        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipChildren="false"
            android:clipToPadding="false">

            <androidx.appcompat.widget.SearchView
                android:id="@+id/searchView"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:focusable="false"
                app:defaultQueryHint="Search by course name or code"
                app:iconifiedByDefault="false"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.appcompat.widget.Toolbar>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/groupList"
        app:layout_constraintTop_toBottomOf="@id/group_fragment_toolbar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_width="0dp"
        android:layout_height="0dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Search fragment:

class GroupFragment : Fragment() {

    private val connection = ConnectionHandler()

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.group_fragment, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val viewModel = ViewModelProviders.of(requireActivity())[SearcherViewModel::class.java]
        val searchBoxView = SearchBoxViewAppCompat(searchView)

        viewModel.groups.observe(this, Observer { hits -> viewModel.adapterProduct.submitList(hits) })

        connection += viewModel.searchBox.connectView(searchBoxView)

        groupList.let {
            it.itemAnimator = null
            it.adapter = viewModel.adapterProduct
            it.layoutManager = LinearLayoutManager(requireContext())
            it.autoScrollToStart(viewModel.adapterProduct)
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        connection.disconnect()
    }

}

Searcher ViewModel:

class SearcherViewModel : ViewModel() {
    val client = ClientSearch(ApplicationID("APP_ID"), APIKey("API_KEY"), LogLevel.ALL)
    val index = client.initIndex(IndexName("groups"))
    val searcher = SearcherSingleIndex(index)

    override fun onCleared() {
        super.onCleared()
        searcher.cancel()
        connection.disconnect()
    }

    val dataSourceFactory = SearcherSingleIndexDataSource.Factory(searcher) { hit ->
        Group(
                hit.json.getPrimitive("course_name").content,
                hit.json.getPrimitive("objectID").content,
                hit.json.getObjectOrNull("_highlightResult")
        )
    }

    val pagedListConfig = PagedList.Config.Builder().setPageSize(50).build()
    val groups: LiveData<PagedList<Group>> = LivePagedListBuilder(dataSourceFactory, pagedListConfig).build()
    val adapterProduct = GroupAdapter()
    val searchBox = SearchBoxConnectorPagedList(searcher, listOf(groups))
    val connection = ConnectionHandler()

    init {
        connection += searchBox
    }
}

Hi @aminhalimah,

Thank you for contacting us.

To fix your issue, you can follow the recommendations we have in our example repo.

You can add and call this function:

fun AppCompatActivity.configureSearchView(
    searchView: SearchView,
    queryHint: String
) {
    searchView.also {
        val hintIcon = ContextCompat.getDrawable(this, R.drawable.ic_search_hint)!!

        it.queryHint = queryHint
        it.setIconifiedByDefault(false)
        it.setOnQueryTextFocusChangeListener { _, hasFocus ->
            searchView.showQueryHintIcon(!hasFocus, hintIcon, queryHint)
        }
        searchView.showQueryHintIcon(true, hintIcon, queryHint)
    }
}