Reputation: 173
why fragment can't hide bottom bar
but activity can hide top and bottom
use the following code :
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
getActionBar().hide();
i try answer 1 but it still not work when i touch my fragment area it will show top and bottom ,let me confused a lot
following is my code: (fragment side)
@Override
public void onCreate(Bundle savedInstanceState)
{
View decorView = getActivity().getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
getActivity().getActionBar().hide();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_ge, container, false);
return rootView;
}
Upvotes: 1
Views: 2645
Reputation: 1370
Ofcourse you can hide the bottom navigation bar.
Here is my recycler scroll listener in my fragment. blogWriteBtn
is my Floatingactionbutton
, don't worry about that.
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0 && blogWriteBtn.getVisibility() == View.VISIBLE) {
blogWriteBtn.hide();
((MainActivity)getActivity()).SetNavigationVisibiltity(false);
} else if (dy < 0 && blogWriteBtn.getVisibility() != View.VISIBLE) {
blogWriteBtn.show();
((MainActivity)getActivity()).SetNavigationVisibiltity(true);
}
}
});
and in my MainActivity
which has bottom navigation bar. I have added this method..
public void SetNavigationVisibiltity (boolean b) {
if (b) {
bottomNavigationView.setVisibility(View.VISIBLE);
} else {
bottomNavigationView.setVisibility(View.GONE);
}
}
It worked perfectly fine for me. Here we called the public method SetNavigationVisibilty(boolean)
of MainActivity
. We can do like this.
Upvotes: 2
Reputation: 401
Chuang, try View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
instead of the other two flags that you have used. This was introduced in API 19 as per my knowledge and will require you to have the minimum SDK version to be same.
Upvotes: 0