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!
Related
I thought that is a solution for that but I cannot find it. I know that I can disable back button by overriding onBackPress() method and not call super.onBackPress() but it only disable, I want to remove/hide from navigation bar this button.
And I known that on some device where the back button is a part of hardware it can be done.
To be clear I mean arrow on below screen:
You can find solution in the documentation.
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
and this code should be placed in onCreate() method in the Activity after initializing all UI elements.
use this code in your onCreate() method : to hide
View bView = getWindow().getDecorView();
bView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
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
I want to hide Bottom Option Bar in Android. I don't know whether we call it Option Bar it or not.
Please check it out Image below : Tell me if we call it something else. It is in bottom.
Now, I want to hide it. How to do it ?
It's called navigation bar, the reason for it only having the options button is probably because your device has hardware buttons for home and back, that's why it looks like an options button only bar.
Refer to the docs for hiding it, although it will only work for versions supporting it.
For 4.0+
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
I have a fullscreen project, and am hiding the statusbar using
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
in the main activity's onCreate.
This works, and hides the status bar just fine, until I add a YoutubeFragment and play a video. The moment the video loads, the status bar drops down, very annoying. I tried setting the flags all over the onInitializationSuccess listener, but no dice. The documentation doesn't mention the status bar on any non-full screen layout changes at all: https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayerFragment
Anyone any ideas?
Thanks in advance.
I don't know if you can put in manifest to hide action bar.
But try this function of Activity class
getActionBar().hide();
I was using a android 4.4.2 device to test with. With 4.1+ or higher there's another way to hide the status bar dynamically : http://developer.android.com/training/system-ui/status.html#41
//4.1+ Specific hiding of status bar
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
I do not have the problem with the status bar popping up when adding a YoutubeFragment. Why the old code didn't work with YoutubeFragments, or even setting the Theme to
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen"
, I have no idea though.
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.