I know how to dim status bar on Android tablets. I do this with that code:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
It works fine but only once. When I touch status bar, it activates and when after that I'm back in my application's activity, status bar is still activated (with icons instead of dots). I tried to log onResume calls, but it's not called, so I googled again and found another solution - using handler for changing visibility of status bar:
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
});
It sometimes works but after several tries it breaks down.
I need this for game - theoretically I can try to call it after every touch or every time in main loop but this seems to be bad idea (and additionally it must be called from specific thread - Only the original thread that created a view hierarchy can touch its views.).
My question is: what is the best way to implement auto dim of status bar? Or, in my situation, any way.
A solution to this is having a View.OnSystemUiVisibilityChangeListener on you root view.
When an event fires you have to wait some time to dim them again. A Timer would be suitable.
private class MySystemUiVisibilityChangeListener implements View.OnSystemUiVisibilityChangeListener {
@Override
public void onSystemUiVisibilityChange(int visibility) {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
MyActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
mRootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
});
}
}, 1000);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With