Issue
I don't want this text while click on search in toolbar.
Below is my menu item.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_search"
android:title="@string/search"
app:actionViewClass="android.widget.SearchView"
app:showAsAction="always" />
</menu>
This is my onCreateOptionsMenu
in Activity
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.search_menu, menu)
val search = menu.findItem(R.id.action_search)
val searchView = search.actionView as SearchView
searchView.queryHint = "Search in everywhere "
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
return false
}
override fun onQueryTextChange(newText: String?): Boolean {
// adapter.filter.filter(newText)
return true
}
})
return super.onCreateOptionsMenu(menu)
}
Very confuse with this. need some help. Thanks in advance for your answer.
Solution
Just add searchView.maxWidth = Integer.MAX_VALUE
this line in my code and it work for me.
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.search_menu, menu)
val search = menu.findItem(R.id.action_search)
val searchView = search.actionView as SearchView
searchView.maxWidth = Integer.MAX_VALUE // add this line to your code.
searchView.queryHint = "Search in everywhere "
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
return false
}
override fun onQueryTextChange(newText: String?): Boolean {
// adapter.filter.filter(newText)
return true
}
})
return super.onCreateOptionsMenu(menu)
}
Answered By - Bhavin Solanki
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.