Immersive mode activity transition - android

I've successfully set the app in the immersive mode because I want to hide the status bar (on the top screen) and the navigation bar (on the bottom screen).
The problem is that when the activity changes the bottom bar automatically arise and immediately after go down and disappear.
I want to avoid this.
All activities have the style AppTheme.NoActionBar set in the manifest:
android:theme="#style/AppTheme.NoActionBar"
And in the OnCreate all have the following code:
getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
GlobalFunctions.setFullscreen(getWindow().getDecorView());
}
});
Where this is the setFullscreen() function:
public static void setFullscreen(View decorView){
int ui_Options = 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_STICKY;
decorView.setSystemUiVisibility(ui_Options);
}
Should I set these attributes before the onCreate in the activity lifecycle? or there are other solutions? or I've implemented the immersive mode in the wrong way?

You don't need to set the global layout listener. Just invoke the setFullscreen function before super.onCreate()

Use this code in manifest activity tag
android:theme="#style/AppFullScreenTheme"
create this style in style.xml
<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:fontFamily">#font/montserrat</item>
<item name="android:windowContentOverlay">#null</item>
</style>
else use this in your activity class
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
this worked for me.

Related

Splash Activity in Android not setting as FULL SCREEN ACTIVITY - Samsung M51

To make the Full-Screen Activity,
So far I have tried it as below :
requestWindowFeature(Window.FEATURE_NO_TITLE)
before setContentView() method in Activity.
Also Tried adding below lines :
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)
But it not worked. Then, I have moved to manifest and Tried as below :
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen"
<activity
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen"
android:name="SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and the stype I have tried above is as below :
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
And Yes, In my layout the Root tag is as below :
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#drawable/bg_layout_screen">
means using android:fitsSystemWindows="true"
Now, the issue is It's not visible as full-screen activity.
The issue screenshot is as below :
[![enter image description here][1]][1][![enter image description here][2]][2]
But Still, the issue is as below Image.
First Image :
[1]: https://i.stack.imgur.com/fbJ2l.jpg
Second Image :
[2]: https://i.stack.imgur.com/ZTpgw.jpg
Black is while adding this line in manifest :
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen"
Please guide. What might be the issue? Thanks.
As per your first image you have to just change the color of your status bar to transperent.
To do it please refer below post
Android Completely transparent Status Bar?
Hope this post helpful to you :)
You can use onWindowFocusChanged() and View decorView = getWindow().getDecorView(); then set SystemUiVisibility.
Example:
//set full screen
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
hideSystemUI();
}
}
private void hideSystemUI() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
// content doesn't resize when the system bars hide and show.
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
// Hide the nav bar and status bar
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
);
}

status bar hinding the layout in android

I want my layout to start below the status bar and expand till the end of screen . Navigation bar should be hidden .
For this i have used this theme :
<style name="AppTheme.NoActionbarThemeDefaultStatusColor" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
</style
for my actiivity.
And i also use below code in the oncreate method of my activity.
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_LOW_PROFILE)
Everything is fine i.e status bar is there , no navigation bar is there .
But the layout's top part is hidden below status bar . I want layout to start after status bar . But not sure how to do this.
Try this code...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
getWindow().setStatusBarColor(Color.TRANSPARENT);
}
}

How to remove title bar from the android activity?

Can someone please help me with the issue.I want my activity as full screen and want to remove title from the screen.I have tried several ways but not able to remove it.
Activity Code :
public class welcomepage extends Activity {
private Button btn;
EditText userName,passWord;
DatabaseHandler dbHandler;
Context ctx =this;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_welcomepage);
}
}
And Activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/pic1"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.edkul.vimal.edkul.welcomepage">
</RelativeLayout>
I want to remove the title bar displayed in blue color .Please find the image for the reference :
AndroidManifest.xml
<application
android:minSdkVersion="3"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.NoActionBar">
<activity
android:name=".welcomepage"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
you just add this style in your style.xml file which is in your values folder
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
After that set this style to your activity class in your AndroidManifest.xml file
android:theme="#style/AppTheme.NoActionBar"
Edit:- If you are going with programmatic way to hide ActionBar then use below code in your activity onCreate() method.
if(getSupportedActionbar()!=null)
this.getSupportedActionBar().hide();
and if you want to hide ActionBar from Fragment then
getActivity().getSupportedActionBar().hide();
AppCompat v7:-
Use following theme in your Activities where you don't want actiobBar Theme.AppComat.NoActionBar or Theme.AppCompat.Light.NoActionBar or if you want to hide in whole app then set this theme in your <application... /> in your AndroidManifest.
In Kotlin:
add this line of code in your onCreate() method or you can use above theme.
supportActionBar?.hide()
i hope this will help you more.
Try this:
this.getSupportActionBar().hide();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try
{
this.getSupportActionBar().hide();
}
catch (NullPointerException e){}
setContentView(R.layout.activity_main);
}
You can try:
<activity android:name=".YourActivityName"
android:theme="#style/Theme.Design.NoActionBar">
that works for me
In your Android Manifest file make sure that the activity is using this (or a) theme (that is based on) #style/Theme.AppCompat.NoActionBar
This removes the ActionBar completely, but won't make your activity fullscreen.
If you want to make your activity fullscreen only use this theme
#android:style/Theme.NoTitleBar.Fullscreen
Or you could change
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
to
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
This is what I use to get fullscreen at runtime
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mDecorView = getWindow().getDecorView();
mDecorView.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 // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
}
To exit fullscreen I use this
mDecorView = getWindow().getDecorView();
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
Add in activity
requestWindowFeature(Window.FEATURE_NO_TITLE);
and add your style.xml file with the following two lines:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
You just add following lines of code in style.xml file
<style name="AppTheme.NoTitleBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
change apptheme in AndroidManifest.xml file
android:theme="#style/AppTheme.NoTitleBar"
For Kotlin you only need this line:
this.actionBar?.hide()
You may use it before setting your content for example:
super.onCreate(savedInstanceState)
//this line is important
this.actionBar?.hide()
setContent {
Box(Modifier.fillMaxSize()) {
.
.
.
You do not need any other changes on XML
Add this two line in your style.xml
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

How can I prevent the Nav Bar from leaving behind a black bar? (immersive mode)

An app that uses immersive mode leaves a black bar at the bottom of the screen when the app is returned to after waiting a while (activity is destroyed).
What is happening: (I have enabled the developer option: "Don't keep activities" to reproduce this).
First time launch of the app. Immersive mode works as expected.
Swipe up to reveal the 'immersive sticky' nav bar, and use the 'Home' button to leave the app. The background of the nav bar briefly shows a black background before the app closes.
Use the 'Recents' button, and select the app to resume it.
The app opens to briefly reveal the nav bar over a black bar. The system ui collapses into immersive mode but the black bar remains.
This bug also only appears on Lollipop, not KitKat.
I have stripped back the app to simply launching a dummy activity with no functionality apart from setting System UI flags:
public class DummyActivity extends FragmentActivity {
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
setSystemUiVisibility();
}
}
public void setSystemUiVisibility() {
if (getWindow() != null && getWindow().getDecorView() != null) {
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_STICKY);
}
}
}
EDIT:
After creating a new fresh project with only this Activity I have seen this issue reproduced when using an app theme extending "android:Theme.Holo"..., and fixed the issue in this sample project when I extend the Material theme instead:
Change
<style name="AppTheme" parent="android:Theme.Holo.Light.NoActionBar.Fullscreen">
</style>
to
<style name="AppTheme"parent="android:Theme.Material.Light.NoActionBar.Fullscreen">
</style>
Unfortunately this fix hasn't solved the issues in my main project, but it brings me closer to a solution and might help others with the same issue.
I was having the same problem. Here are a few updates I made which made it go away. Hopefully one of these works for you!
activity_main.xml
android:fitsSystemWindows="false"
style-v21
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowSharedElementsUseOverlay">false</item>
MainActivity.java
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_FULLSCREEN
);
For me it was a black bar at the top. Key thing was this in the activity style:
// Important to draw behind cutouts
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
Here is my code:
1- In Activity
private fun hideSystemUI() {
sysUIHidden = true
// 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
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// Hide the nav bar and status bar
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // Hide nav bar
or View.SYSTEM_UI_FLAG_FULLSCREEN // Hide status bar
)
}
private fun showSystemUI() {
sysUIHidden = false
window.decorView.systemUiVisibility = (
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // layout Behind nav bar
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // layout Behind status bar
)
}
2- In root view of xml layout
android:fitsSystemWindows="false"
3- Style for the Full screen Activity:
<style name="FullscreenTheme" parent="AppTheme">
<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>
<item name="android:statusBarColor">#50000000</item>
<item name="android:navigationBarColor">#50000000</item>
// Important to draw behind cutouts
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#color/sysTransparent</item>
</style>
Using
<style name="AppTheme"parent="android:Theme.Material.Light.NoActionBar.Fullscreen"> </style>
does solved the problem, but it only work for api:21.
In order to make it works for all system. You can create a directory called style-v21 in res directory, and put that style.xml there. Android system is smart enough to pick which one to use for new or old phone.

Immersive fullscreen below 4.4

I have an app that I want to run in fullscreen. If i have a device with 4.4 KitKat it is easy to set the SYSTEM_UI_FLAG_IMMERSIVE to make the app go pure fullscreen.
However if i have a device with a lower API than 4.4. I have no idea how to make it fullscreen as if it was a KitKat with Immersive support.
I can set the Fullscreen, and hide navigation flags to make the app go fullscreen, but as soon as the screen is clicked, these flags are reset and will now show both navbar and statusbar.
Is there a solution where i can "simulate" the immersive mode on devices with JB and possibly ICS (not necesserily below).
I have a method hideSystemUI which runs when OnSystemUiVisibilityChangeListener triggers which look like this at the moment.
private void hideSystemUI() {
actionBar.hide();
isMenuVisible = false;
if (currentapiVersion >= android.os.Build.VERSION_CODES.KITKAT){
mDecorView.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);
}
else{
mDecorView.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);
}
}
What changes do I need to make to make the app go fullscreen and not showing navbar and statusbar on every click, but rather on slide from top or bottom.
This is as close as you're going to get:
if (Build.VERSION.SDK_INT >= 19) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
} else {
if (Build.VERSION.SDK_INT > 10) {
findViewById(android.R.id.content).setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
}
And don't support devices with an SDK less than 10. Those jokers need to get a modern android anyway.
I had faced the same situation and after some research i figured out it is not possible below 4.4 because of security issues, and so old APIs wont support hiding navigation bar the way you want.
Even though from API 4.1 your use of SYSTEM_UI_FLAG_LAYOUT_STABLE flag your layout won't resize and it will inflate behind navigation bar, but you need to make sure none of your important UI components are covered by it.
https://developer.android.com/training/system-ui/immersive.html
Hope this helps..:)
just copy past below code into value/style.xml.
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
There are two method for immersive mode
To make it remain immersive do change thid line
View.SYSTEM_UI_FLAG_IMMERSIVE
By this line-
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY

Categories

Resources