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

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
);
}

Related

Android glitch opening app with full screen and list views

I have configured my application and activities to work on full screen mode, but I'm finding with a problem I can't solve.
When my App starts up it goes from a loading screen to home screen, everything ok, but If I press "home" button and comeback to my App (no loading screen now, app it's started) then the layout is displaced by the status bar, and my bottom bar is cut. This effect lasts like 0.5-1 sec.
This also happens when a heads up notifications shows up.
My research points to listviews or similiar views, like viewpager.
It just happened on my activities with listviews, then I changed my activity to manage fragments on a view pager, tried again and now happens in every single fragment, I mean my 3rd page is a simple fragment and it didn't happen on that one, but now with view pager it does.
I have all my activies with the same theme on manifest:
<activity
android:name=".OpenActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
styles.xml
<style name="AppTheme.FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowEnableSplitTouch">false</item>
</style>
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#android:color/transparent">
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/navbar_space" />
<fragment
android:id="#+id/nav_bar_fragment"
android:name="es.udc.psi1516.pickapp.navbar.NavBarFragment"
android:layout_width="match_parent"
android:layout_height="#dimen/navbar_height"
android:orientation="horizontal"
android:layout_alignParentBottom="true" />
</RelativeLayout>
I have some code on my MainActivity.java to hide status bar:
#Override
protected void onResume() {
super.onResume();
hideSystemUI();
}
// This snippet hides the system bars
public void hideSystemUI() {
int newUiOptions = getWindow().getDecorView().getSystemUiVisibility();
newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
}
And it only happens when you enter the App from App Icon, if you comeback from android task view it works nice. I gave up but if you have any ideas I would try anything.
After a lot of testing I have found the solution.
I have had to remove the fullscreen property from xml styles, that was applying some internal states that broke my app screen.
And now I have to manage the state just in code.
Remove android:fitsSystemWindows="true" so my layout doesn't leave extra space for status bar.
Remove android:windowFullscreen from style, now it looks like this:
<style name="AppTheme.FullScreen" parent="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Change code of flags to override current state on onResume(), I was adding flags to current state, don't ask me why, probably some copy-paste fail:
private void hideSystemUI() {
int newUiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
}

Immersive mode activity transition

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.

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>

Is it possible to use not only status bar but the footer navigation view also for background image

I have searched everywhere but didn't get any help. I want to use a background image as full screen which will cover status bar and the footer navigation also which having a back button with home button and a task switcher button.
Like below image:
Transparent navigation bar work for Android 4.4+ (API 19) (just like status bar).
values/styles.xml
<style name="FullScreenEffectTheme" parent="Theme.AppCompat.NoActionBar">
<!-- ... -->
</style>
values-v19/styles.xml
<style name="FullScreenEffectTheme">
<!-- StatusBar -->
<item name="android:statusBarColor">#android:color/transparent</item>
<!-- NavigationBar -->
<item name="android:navigationBarColor">#android:color/transparent</item>
</style>
In code set flags:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
}
Don't forget to set this style to activity :)
Then you need to add padding or Space to your layout.
Important: If you want to have landscape orientation for phones translucent navigation bar cause ugly issue and in this case you should off this feature. I solved it like Tanner Perrien explained here.

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.

Categories

Resources