There are several ways to achieve this, but one simple method is to use the setOnFocusChangeListener
method with the getWindow()
method to get the window of the current activity and then set the visibility of the bottom navigation bar as needed.
Here's an example implementation:
searchView.setOnQueryTextFocusChangeListener((view, hasFocus) -> {
if (hasFocus) {
getWindow().getDecorView().findViewById(R.id.bottom_navigation).setVisibility(View.GONE);
} else {
getWindow().getDecorView().findViewById(R.id.bottom_navigation).setVisibility(View.VISIBLE);
}
});
In this example, we set a OnFocusChangeListener
for the searchView
and check if it has focus. If it does, we use the getWindow()
method to get the current activity window and then retrieve the bottom_navigation
view by calling findViewById
. We then set its visibility to GONE
(i.e., hide it). When the searchView
loses focus, we set the visibility of the bottom_navigation
view to VISIBLE
again.
You can use a similar approach for handling the dialog focus as well. Simply set a focus change listener for the dialog's searchView or any other view that you want to hide the bottom navigation for.
Asked: 2023-07-06 07:40:21 +0000
Seen: 8 times
Last updated: Jul 06 '23