How to hide the action bar (Theme.Holo) if the Android version is lower than 3.0

I noticed that the action bar (Theme.Holo) looks cool only in Android 3.0 or higher, but it is not like it, for example, for Android 2.3.

Is it possible to display the action bar (Theme.Holo) based on the Android version?

+5
source share
2 answers

This is because an ActionBar was not added before Android 3.0 (API level 11), so any version of Android is lower than it will have a title bar and not an action bar.

ActionBar is not yet part of the official compatibility library, so at the same time, the ActionBarSherlock library will allow you to have an ActionBar that looks the same in all versions of the API.

If you want to hide the ActionBar just add the addition of android: style / Theme.Holo.NoActionBar to the actions in the manifest.

+4
source

The action bar requires a minimum of API 11. If you want to remove it programmatically, although you can use hide () in the code for this action.

ActionBar actionBar = getActionBar(); actionBar.hide(); 

Not quite sure what it will show for anything below 3.0, but it seems like the best place to start.

Edit:

You can check the SDK version at runtime using build constants

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { //checks if its lower than Honeycomb ActionBar actionBar = getActionBar(); actionBar.hide(); } 
+5
source

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


All Articles