How to disable the navigation bar slide animation when going fullscreen? - android

I have an activity that goes to another full screen activity. However, when transitioning from this activity to my full screen activity, the navigation bar slides down instead of disappearing instantly. I've inflated a full-screen window in the second activity, but because of the slow sliding animation, it resizes 1 second later after the animation has completed instead of being inflated to full-screen immediately. Therefore, I need the animation to disappear instantly. I've tried
<item name="android:windowAnimationStyle">#null</item>
and
overridePendingTransition(0, 0);
and
Transition fade = new Fade();
fade.excludeTarget(android.R.id.navigationBarBackground, true);
getWindow().setEnterTransition(fade);
with no luck.
On the Windows side, I've tried
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
WindowManager.LayoutParams.FLAG_FULLSCREEN
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
How I hide the navbar: View.SYSTEM_UI_FLAG_HIDE_NAVIGATION

I think, I nailed it:
FullscreenActivity class:
public class FullscreenActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
decorView.setSystemUiVisibility(uiOptions);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
setContentView(R.layout.activity_fullscreen);
}
}
Manifest:
<activity
android:name=".FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_fullscreen"
android:theme="#style/FullscreenTheme"/>
Styles:
<style name="FullscreenTheme" parent="AppTheme">
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:actionBarStyle">#style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
NB! Setting StatusBar colour required API 21. For the older versions, to "hide" StatusBar, you need use:
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
as uiOptions in the code above. (it'll cause quite quick resizing, though).
I hope, it helps

Related

Android - A strange artifact in full screen on some devices

When running on Android 10 emulator and Galaxy S8 physical device (running Android 9), the next code works perfectly fine. Nevertheless, on Motorola Moto G8 (running Android 9) entering full screen mode, all view's content goes down and in place of status bar blank black space appears.
Galaxy G8, normal and full screen views:
Motorola Moto G8, normal and full screen views:
As you can see, on motorola g8 screen goes down the size of status bar and on top of screen appears blank black screen.
Here is Android manifest:
android:theme="#style/AppTheme"
Here's styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<!--Required Api 21 above-->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
</resources>
Layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:onClick="onButtonClick"
android:src="#drawable/llama" />
</RelativeLayout>
Activity class:
public class MainActivity extends AppCompatActivity {
private boolean isFullScreen;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
isFullScreen = false;
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
isFullScreen = true;
}
}
});
}
#Override
protected void onResume() {
super.onResume();
}
// onWindowFocusChanged()
public void onButtonClick(View view) {
if (isFullScreen) {
showSystemUI();
} else {
hideSystemUI();
}
}
private void hideSystemUI() {
// Enables regular immersive mode.
// For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
// Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
}
// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
}
The whole project is available at Github: https://github.com/alecpetrosky/Android-Immerse-Demo
add below code after function setContentView
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}

Android - Making activity full screen with status bar on top of it

I want to make my activity full screen with status bar on top of it like this picture:
I have used this code in manifest inside activity tag:
'android:theme="#style/Theme.AppCompat.Light.NoActionBar"'
But my view doesn't start from the status bar & it looks like this:
How can I make my activity look like the first one?
I know that the guy asking the question may have found his own solution but for the people who are still looking for a solution this is a very simple solution but one thing it has a limitation till Kitkat so a condition is added
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
Add these to your Base Application Theme in styles.xml
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
And add following attribute to your parent layout:
android:fitsSystemWindows="false"
Hope this helps.
If you dont want your "Translucent navigation" transparent, here is the code to just make transparent the status bar
In your theme:
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
In your activity onCreate:
Window window = getWindow();
WindowManager.LayoutParams winParams = window.getAttributes();
winParams.flags &= ~WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
window.setAttributes(winParams);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
1. Transparent Statusbar
window?.decorView?.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
window.statusBarColor = Color.TRANSPARENT
2. Transparent Statusbar & Bottomnav bar
window.setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
);
3. Hide Statusbar
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.insetsController?.hide(WindowInsets.Type.statusBars())
}
else {
#Suppress("DEPRECATION")
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
}
4. Hide Statubar & Bottomnav bar
val actionBar: ActionBar? = supportActionBar
if (actionBar != null) actionBar.hide()
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LOW_PROFILE
or View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)
where to put this code ?
override fun onCreate(savedInstanceState: Bundle?) {
/* Put above code here ..... */
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_slider)
}
Note
I checked this code in Pixel 3A emulator
Maybe customise android OS not support
set styel <style name="Theme.FullScreen" parent="Theme.MaterialComponents.DayNight.NoActionBar">
To achieve something similar to this, use this:
1. Your Activity Theme
<style name="FullScreenTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowActivityTransitions">true</item>
</style>
2. There is NO NEED to add android:fitsSystemWindows property into your root layout XML file.
3. In your Activity
Add padding top to your toolbar. I am using custom toolbar, so I am adding padding to my toolbar of the height of statusbar.
toolbar.setPadding(0, getStatusBarHeight(), 0, 0)
and the function getStatusBarHeight() is added in my Utils class
fun Activity.getStatusBarHeight(): Int {
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
return if (resourceId > 0) resources.getDimensionPixelSize(resourceId)
else Rect().apply { window.decorView.getWindowVisibleDisplayFrame(this) }.top
}
put below of code inside onCreate()
private void setStatusBarTransparent() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
View decorView = window.getDecorView();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
window.setStatusBarColor(Color.TRANSPARENT);
}
}
Try Like This
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Hope this one will help
In Kotlin just use following code in your activity, also add android:fitsSystemWindows="true" in your parent view of activity.xml layout file.
This will also show content over navigation bar too, provided you declared full screen style in your style.xml
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
window.setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
)
}
you can use this code after onCreate
setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
your activity will be fullscrean with status bar :)
#tahsinRupam answer is correct and tested on post Kitkat version.
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
If you want to use it only for a certain activity, create a style, and attach it on your manifest style like this.
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/Activity.Fullscreen.Theme" />
<style name="Activity.Fullscreen.Theme" parent="MyMaterialTheme.Base">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
Thumbs up on origal #tahsinRupam
Happy codings Cheers !
Put this code in your Activity onCreate this will hide the status bar
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();

How to prevent toolbar and navigation bar blinking during shared view activity transition?

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- enable window content transitions -->
<item name="android:windowContentTransitions">true</item>
<item name="android:windowActionBarOverlay">false</item>
<item name="android:windowSharedElementsUseOverlay">false</item>
</style>
or
excluding from java class navigation and statusbar from transition
View decor = ((PhotosActivity)context).getWindow().getDecorView();
View statusBar = decor.findViewById(android.R.id.statusBarBackground);
View navBar = decor.findViewById(android.R.id.navigationBarBackground);
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation((PhotosActivity) context,
new android.support.v4.util.Pair<>(photo, "photo")
new android.support.v4.util.Pair<>(statusBar, Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME),
new android.support.v4.util.Pair<>(navBar, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME));
);
context.startActivity(photoIntent, options.toBundle());
it continues blinking
View decor = getWindow().getDecorView(); this decor view used to get the default action bar.
makeSceneTransitionAnimation used to define the shared widgets between the two activities.
To prevent flickering for action bar, status bar and navigation bar. Please add these lines of code in the onCreate method for the 2 Activities:
Fade fade = new Fade();
View decor = getWindow().getDecorView();
fade.excludeTarget(decor.findViewById(R.id.action_bar_container), true);
fade.excludeTarget(android.R.id.statusBarBackground, true);
fade.excludeTarget(android.R.id.navigationBarBackground, true);
getWindow().setEnterTransition(fade);
getWindow().setExitTransition(fade);

Hide status bar in windowmanager

Please,somebody,tell me how to hide/disable status/notification bar using onluWindowManager, do not using WindowManager.LayoutParams.FLAG_FULLSCREEN, AndroidManifest or something that is not WindowManager.
this worked for me, but i had to call the method every time i wanted to make sure the flag was like this
anyViewInTheLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
Put this line in your activity onCreate() method above setContentView() :
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
Hope it help!
use this as a style:
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
You can do it programmatically like this:
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
More info on official pages: http://developer.android.com/training/system-ui/status.html
You can put these code in your onCreate() method of your activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
}
}
Hope it help!

Android Immersive Mode Transitions

I have an android app which uses immersive mode for all activities - so its a full fullscreen app.
I have a BaseActivity class from which all other activities extend. In this activity I call the following to enable fullscreen/immersive
HelmiBlankActivity:
private boolean apiLowerImmersive = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
apiLowerImmersive = true;
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus && !apiLowerImmersive ) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
}
In activities it works great, the problem is: When opening a new activity (per intent) the actionbar/titlebar are displayed for a short time and then hidden again - which seems kind of laggy/buggy.
The Application also has a theme:
styles.xml:
<style name="FullscreenTheme" parent="android:Theme.Holo.Light">
<item name="android:windowFullscreen">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
I have tried applying the android:Theme.Holo.Light.NoActionBar as well - no success during transitions.
I could not find anything on stackoverflow (which btw is a great community and has helped me with many problems) or anywhere else on the internet and would appreciate your help.
If you put this snippet into onCreate() method your activities will open with the bars already hidden.
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
You can also add conditions for older SDKs. The only problem I've got with this setup is the fact that once i swipe down to show bars, they won't hide again...

Categories

Resources