当我单击SearchView时如何隐藏FAB 因此FAB会在键盘打开时显示
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="18dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="8dp"
android:scaleType="center"
android:layout_marginRight="8dp"
android:src="@drawable/ic_add_operator"
app:backgroundTint="@android:color/transparent"
app:layout_constraintEnd_toEndOf="parent"
/>
答案 0 :(得分:1)
我一直在寻找相同的解决方案,并且想出了这个解决方案,它对我的SearchView
来说很好用。检出(Kotlin
版):
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
val search: SearchView =
menu!!.findItem(R.id.action_search_main).actionView as SearchView
search.apply {
imeOptions = EditorInfo.IME_ACTION_DONE
isSubmitButtonEnabled = true
setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(p0: String?): Boolean {
return false
}
override fun onQueryTextChange(p0: String?): Boolean {
// My Function
return false
}
})
}
val menuItemSearch = menu.findItem(R.id.action_search_main)
menuItemSearch.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
override fun onMenuItemActionExpand(item: MenuItem?): Boolean {
Log.wtf("FAB", "HIDE")
fab.hide()
return true
}
override fun onMenuItemActionCollapse(item: MenuItem?): Boolean {
Log.wtf("FAB", "SHOW")
fab.show()
return true
}
})
return super.onCreateOptionsMenu(menu)
}