Android 4.0: setting SYSTEM_UI_FLAG_LOW_PROFILE &

2019-05-25 03:38发布

问题:

I am playing around with controlling the UI Navigation buttons in ICS.

The current mechanism for suppressing the Nav Buttons is to call setSystemUiVisibility from a View using the SYSTEM_UI_FLAG_HIDE_NAVIGATION or SYSTEM_UI_FLAG_LOW_PROFILE flags. This seems like a strange place for setting these flags, as most other related settings (such as hiding the status bar) have been done through window LayoutParams properties.

My question is if any of you have ideas for a good way to do it from an Activity context. Currently my app is designed to start with a base activity class which contains any functionality I want throughout my entire application. Specific Activities are then derived from that base class. I would like to be able to set the UI nav flags from that base Activity so I don't have to do it in multiple spots throughout my source code... but my base Activity does not contain any View objects.

As a secondary statement, what I would really like to be able to do is completely remove the NAV buttons (such as using SYSTEM_UI_FLAG_HIDE_NAVIGATION) and not have them come back on user input (giving my app complete control over the UI). I know this is not something that any app from the market should be able to do... but I am not developing something that will available via the market. My current plan involves a custom build of the OS that will allow me to accomplish this, but it would be nice if there was some method of eliminating those soft buttons in the meantime.

Thanks!

回答1:

This is what I put in onCreate of my activities:

View main_layout = dialog.findViewById(android.R.id.content).getRootView();
main_layout.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);

It's almost like calling it from an activity context. At least it's not dependent on having a view defined at compile time. I know STATUS_BAR_HIDDEN is deprecated, but I can't get SYSTEM_UI_FLAG_LOW_PROFILE to compile at the moment...

But +1 on the "this seems like a strange place for these settings". Should be something you can define in the manifest once for the entire app.



回答2:

You can't completely remove the ICS navigation buttons.

You can hide them completely, but they'll reappear as soon as you touch the screen:

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

Unfortunately, some ICS UI layers like Samsung's TouchWiz won't recognize SYSTEM_UI_FLAG_HIDE_NAVIGATION.

Alternatively, you can minimize them and they'll only appear when the bar it tapped:

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

You'll probably have to build your own ROM to eliminate them completely.