SearchView looks fine on Lollipop devices (Android 21):
But on Android 23-28 it doesn't hide all icons on the right side:
<item android:id="@+id/action_search"
android:title="@string/search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="ifRoom"/>
<item android:id="@+id/action_sort"
android:title="@string/sorting"
android:icon="@drawable/sort"
app:showAsAction="ifRoom"/>
How can I fix it?
Update
Seems Android 23 and higher don't hide icons anymore on the right (because there is enough space)
But it only works fine if you don't have home button or hamburger menu on the left:
But I have an icon on the left and that's why my action bar looks ugly when SearchView is expanded:
Should be a bug in newest Android ActionBar design...
I add menu button like this:
supportActionBar?.let {
it.setDisplayHomeAsUpEnabled(true)
it.setHomeAsUpIndicator(R.drawable.ic_menu)
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…