How to disable notification bar and status bar on lock screen? - android

I have tried the following code but still it will not work properly for me.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

You may try the following,
View view = getWindow().getDecorView();
// Hide the Status bar
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
view.setSystemUiVisibility(uiOptions);
// Hide ActionBar
ActionBar actionBar = getActionBar();
actionBar.hide();
or Simply add the style in manifest,
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen"

Related

Hide status bar not work

I use SYSTEM_UI_FLAG_FULLSCREEN to hide status bar, code like this(sdk > 16):
Decorview decorview = getWindow().getDecorview();
decorview.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
However, it works on some Android phones but fails on others like below:
What is wrong with the white satus bar? Why is it not hidden?
ps: The style is ok, just a normal one, no fitwindowsystem, no immersive.
As mentioned in the Android Docs, you can hide the statusBar like this in SDK < 16 i.e Android version lower than Jellybean :
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
call this in your onCreate method, before you call setContentView.
and for SDK above 16 use the following code :
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();
1.If the Android version is lower than Jellybean, use this call to hide.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
}
2.Code to hide the Status Bar on 16 and Higher your Code works.
Decorview decorview = getWindow().getDecorview();
decorview.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
Note : 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();
3.if the status bar should always remain hidden in your app setting an activity theme in your app's manifest file.
<application
...
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>

How to remove a notification panel in android

How to make simple android app,that can be disable all thing of notification panel
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();

hide and show statusbar without any effect to layout in android

I want to write a book-reader application that normally runs in full-screen, but when user touched screen, status bar become visible OVER my main layout without re-creating the whole view.
I already read these but no help at all:
Hide notification bar without using fullscreen
Hide Notification bar
Android Show Activity Title/status bar at the top after it is hidden
any idea how can I do it?
thanks
finally, I did it!!
these 2 methods will show and hide status bar without destroying the layout.
you need to set
private View mMainView; // The main view of the activity
private int mSystemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
then
/** Hides StatusBar and ActionBar */
private void hideSystemUi() {
ActionBar ab = getActionBar();
ab.hide();
// Set flags for hiding status bar
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
// Hide the status bar.
mMainView.setSystemUiVisibility(uiOptions);}
and
/** Shows StatusBar and ActionBar */
private void showSystemUi() {
ActionBar ab = getActionBar();
ab.show();
// Reset flags
mMainView.setSystemUiVisibility(this.mSystemUiVisibility);
}
and put this in your onCreate() method:
mMainView = findViewById(R.id.mainLayout);
mMainView.setSystemUiVisibility(mSystemUiVisibility);

How hide and show status bar

Just it, I have found how to hide title bar but I didnt find how hide / show the status bar pressing a button fr example. It is possible? thanks!
For poeple whose show part is not working , You can try following code
Show Status Bar
if (Build.VERSION.SDK_INT < 16) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
View decorView = getWindow().getDecorView();
// show the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
decorView.setSystemUiVisibility(uiOptions);
}
To hide a status Bar
Use this code in your Activity
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Change Application theme in Manifest file as below
android:theme="#android:style/Theme.Black.NoTitleBar"
Reference - https://developer.android.com/training/system-ui/immersive.html
// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
Although action bar is overlayed with the status bar.

Hide status bar while having Media controller on android

i am using this method to hide status bar :
public static void hideStatusBar(Activity activity) {
if (Build.VERSION.SDK_INT < 16) {
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
View decorView = activity.getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
}
this works fine but when i start video i have notice the status bar is visible again , after some test on my code i have realized that the status bar i visible after i add the MediaController .
how can i keep my full screen and still using MediaController ?
this is how i add the MediaController
mMediaController = new MediaController(getContext());
mMediaController.setAnchorView(this);
setMediaController(mMediaController);
use:
<application
...
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>
or
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();
and see this link:
http://developer.android.com/training/system-ui/status.html
and this link:
How to hide status bar in Android
Yes, the videoView can bring back the status bar. Not sure what the behind principle is. While you can resolve it by setting a setOnSystemUiVisibilityChangeListener, Something like:
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
);
}
});

Categories

Resources