Repeatedly dull status bar (SYSTEM_UI_FLAG_LOW_PROFILE) on tablets in full screen?

I know how to hide the status bar on Android tablets. I am doing this with this code:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); 

It works fine, but only once. When I touch the status bar, it is activated, and when after that I return to my activity, the status bar is still activated (with icons instead of dots). I tried to enter onResume, but it was not called, so I searched googled again and found another solution - using a handler to change the visibility of the status bar:

 getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); } }); 

Sometimes it works, but after several attempts it breaks.

I need this for the game - theoretically I can try to call it after every touch or every time in the main loop, but this seems like a bad idea (and, in addition, it should be called from a specific thread - only the original thread that created the presentation hierarchy can touch his representations.).

My question is: what is the best way to implement automatic anti-aliasing of the status bar? Or, in my situation, anyway.

+6
source share
4 answers

The solution to this issue is View.OnSystemUiVisibilityChangeListener in the root view.

When the event fires, you need to wait a while to darken them. The timer will 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); } } 
+2
source

I also came across this problem (but for the hidden navigation flag), and it seems that google initially disabled the ability to constantly hide / smooth the system panel. I agree with you that a constant call to this method can lead to a crash in threads or cause performance problems, especially considering the fact that so many ontouch events are happening on a mobile device.

Ultimately, I do not think that there is a solution for this if the user has not rooted his device to permanently remove the system panel.

0
source

I changed Caranlos a bit:

 Timer timer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { AudioRecordTest.this.runOnUiThread(new Runnable() { @Override public void run() { if (ivIndicator.getVisibility() == View.VISIBLE) ivIndicator.setVisibility(View.INVISIBLE); else if (ivIndicator.getVisibility() == View.INVISIBLE) ivIndicator.setVisibility(View.VISIBLE); } }); } }; timer.scheduleAtFixedRate(task, 0, 500); 

you don’t need to create a new class or implement anything. just make a TimerTask , as in his answer, and schedule it using scheduleAtFixedRate(task, delay, period) , this method will run TimerTask every period time in milliseconds.

0
source

Not sure if this was available back in 2012, but now you can use the onWindowFocusChanged() callback onWindowFocusChanged() :

 override fun onWindowFocusChanged(hasFocus: Boolean) { super.onWindowFocusChanged(hasFocus) if (hasFocus) window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE } 
0
source

Source: https://habr.com/ru/post/928195/


All Articles