I have an android activity extended from ActionBarActivity.
My Activity content ruled by state pattern. When state changes, screen also changes somehow. I need ActionBar just in one of 3 states I have. How can I hide ActionBar by default and show it only in one State of my Activity?.
Thanks in advance!
For hiding use
getSupportActionBar().hide();
and for Showing it again use
getSupportActionBar().show();
look at this example its work for me by default i hide my action bar layout after that i am showing it on user data requirements
How to hide and show action bar
Related
I want to hide the statusbar from all layouts on click of button.That button i have define in setting layout. But on click of hide button the status bar of current layout is getting hide but on other layout is unaffected.So let me know how to implement it on all the layouts of mu app.
Create a superclass for all Activities, call it something like BaseActivity or AbstractActivity and make each activity extend this class
In the onCreate, before setContentView, read from a database like SharedPreferences whether the status bar should be hidden. If so, then hide it.
In your Settings activity, call recreate() so that each onCreate from the previous activities are called again.
It actually depends on the version of android you are using. For example in Android 4.0 and lower you can achieve it by doing:
<application
...
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>
For full documentation go to: https://developer.android.com/training/system-ui/status
Edit: What would be better for your button is this code:
void HideStatusBar() {
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();
}
So, when the user clicks the button call this function. Remember this also hides the action bar or toolbar, so if you don't want that remove the actionbar.hide() part. It's nice, but unfortunately, it only works on Android 4.1 and higher, so if you are supporting lower versions too better look at the documentation for clues. Hope it helps!
I'm using ViewPager to display tabs in Android, but in a circumstance, I want to display a fragment on top of the pager/tabs, but NOT on top of the ActionBar. If I hide the action bar, they both disappear. If I don't do it, I can't find a way to get rid of pager's tab bar (or whatever it's called). Here is a visual representation of what I'm trying to achieve:
How can I hide that bar without hiding the action bar?
I think you can do it by setting a new navigation mode.
Use setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD) to hide them
Use setNavigationMode(ActionBar.NAVIGATION_MODE_TABS) to show them again
Edit:
Please note that the setNavigationMode methods are deprecated in Android Lollipop.
Reference
Use this to get rid of tabs in actionbar
setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD)
I have a typical case where I have used SherlockActionBar for horizontal scrolling. I want the title bar**(one where it depicts the android default icon and app name)** in my activity to disappear. To be more clear, I do not want the bar that is present at the top of the screen but I use a action bar next to it for navigation which is vital. How do I make the top one disappear ? Any ideas will be highly appreciated. An example image is given below :
I hope the question is clear. Feel free to ask for more.
to hide programmatically AB/ABS you can use
getSupportActionBar().hide();
if you are not using support libraries
getActionBar().hide();
otherwise
getSupportActionBar().hide();
NOTE: if your activity extends SherlockFragmentActivity then only the getSupportActionBar().hide(); method will be visible otherwise you will get only getActionBar().hide(); that works with minimum API level 11.
if you are using Action bar (API Level>11)
getActionBar().hide();
or if you are using actionbar sherelock lib (API Level <11)
getSupportActionBar().hide();
Credits goes to blackbelt(answer was delvered via comments) :
getSupportActionBar().setDisplayShowHomeEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(false);
Calling these functions would remove the title bar. This removed my title bar but the action bar was safe and sound. Thanks to blackbelt.
I have an action bar set up in the main activity, and this creates a bunch of fragments. However, there are several fragments that require the action bar to be hidden, but I can't refer to the ActionBarSherlock class inside a fragment.
How can I hide the action bar?
Thanks for any suggestions.
Actually you can refer to ActionBar via activity which you can get from a SherlockFragment by calling SherlockFragment.getSherlockActivity(), then just call SherlockFragmentActivity.getSupportActionBar() and then hide()
Is it possible to use fragment tabs on action bar with the Theme.Holo.NoActionBar theme?
I mean... I already use this theme on my layouts but apparently it is overriden since the fragments have to show up in the action bar?
What I wanted to achieve is to actually get rid of the Title and App Icon over the fragment tabs. Something similar to the Google Music app.
Is this possible?
What I wanted to achieve is to actually get rid of the Title and App Icon over the fragment tabs. Something similar to the Google Music app.
Try calling setDisplayShowHomeEnabled(false) and setDisplayShowTitleEnabled(false) on your ActionBar, and leave the theme alone.
You can style the action bar based on your needs. I'm quite certain you can also remove the app icon and title from there. Using a NoActionbar theme by default and then recreating the action bar on your own kinda defeats the purpose of the action bar. I suggest you use a theme with action bar and then style the bar according to your needs. This page has a decent implementation.