Reputation: 5792
I have MainActivity
extends AppCompatActivity
. In that 3 fragments which can be changed by sliding gesture. I want to remove action bar in middle one. And Add action bar again when user slide in 1st or 3rd fragment.
I have below code:
@Override
public void setMenuVisibility(boolean menuVisible) {
super.setMenuVisibility(menuVisible);
if(menuVisible && getActivity()!=null){
getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
@Override
public void setMenuVisibility(boolean menuVisible) {
super.setMenuVisibility(menuVisible);
if(menuVisible){
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
But, it's giving me below warning:
Skipped 45 frames! The application may be doing too much work on its main thread.
I tried to put that in:
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// hide / show action bar...
}
});
App is lagging. How can I make it smooth?
Upvotes: 0
Views: 3251
Reputation: 1739
Add the following code snippet in the onResume
callback of the middle Fragment
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity != null) {
activity.getSupportActionBar().hide();
}
and in the onResume
callback of the other two Fragment
s add
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity != null) {
activity.getSupportActionBar().show();
}
Upvotes: 1