Android glitch opening app with full screen and list views - android

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

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

True Fullscreen not working with AppCompat theme in Android?

I'm trying to create a splashcreen for my android application. I'm using an AppCompat theme, and I read that to have it fullscreen, I have to use in my style.xml theme (which I did):
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
With that, my application starts in fullscreen in the sense that when it starts, there is a white screen (in fullscreen) that appears before my splashscreen.
However, when my splashscreen starts, there is a black bar on top (which is where the status bar is) (cf screenshot)
My splashscreen is pretty simple:
<?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"
android:background="#color/cardview_shadow_end_color"
tools:context=".ui.activity.SplashscreenActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_logo_galagomusic"
android:scaleType="centerCrop"
android:layout_centerInParent="true"/>
</RelativeLayout>
I tried to add in the splashscreen activity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
window.decorView.apply {
// 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.
systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_FULLSCREEN
}
supportActionBar?.hide()
setContentView(R.layout.activity_splashscreen)
}
But it still doesn't work.
I'm not sure what is going on here, if anybody can help, that would be great.
Thanks.
Edit: It seems to be related to this issue: How to remove top status bar black background
This issue come from the phone itself, which allow or not some application to go fullscreen.
https://www.gottabemobile.com/how-to-enable-full-screen-apps-on-galaxy-s10/
Is there a way to override that?

Hiding navigation bar after showing menu on API > 24

I'm stuck into a funny issue. I need to hide the navigation and status bar on my app. After several unsuccessfull trials trough layout xml coding I did it by code in this way:
private void setVisibilityOptions() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| 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);
}
I'm calling this into onResume() event handler because the Activity is derived from AppCompatActivity and it works.
The funny part comes when the app menu shows up. This immediatly triggers system to show-up navigation and status bar. Then if I select an item on the menu that retriggers a resume event I'm safe and status and navigation bars are hidden again, but if I do not select a menu item they stand there (with an horrible graphical effect among other things).
I tought to use onOptionsItemSelected event handlers but of course it's not triggered if no items is selected. onOptionsMenuClosed is not triggered at all.
I'm adding menu layout and toolbar section for reference:
Menu:
<menu 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"
tools:context="xxx.MainActivity">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never" />
<item
android:id="#+id/action_drivers"
android:orderInCategory="100"
android:title="#string/action_drivers"
app:showAsAction="never" />
<item
android:id="#+id/action_controller"
android:orderInCategory="100"
android:title="#string/select_controller_title"
app:showAsAction="never" />
<item
android:id="#+id/action_map"
android:orderInCategory="100"
android:title="#string/map_title"
app:showAsAction="never" />
<item
android:id="#+id/action_telemetry"
android:orderInCategory="100"
android:title="#string/telemetry_title"
app:showAsAction="never" />
</menu>
Application bar:
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay" >
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
BTW. The main activity is derived from AppCompatActivity and this's not able to trigger WindowsFocusChanged events.
How can I fix this?
Is it possible to catch an event when the menu closes?
What about onPrepareOptionsMenu? Perharps you could call your setVisibilityOptions() there.
So, in theory, onPrepareOptionsMenu get's called, navigation and status bar become visible, but then you call setVisibilityOptions() so they become invisible again and hopefully this happens too fast for the user to notice.

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>

Transparent status bar not working with windowTranslucentNavigation="false"

I am developing an Activity where I need to make the navigation bar opaque, and the status bar transparent on devices running 5.0+ (API 21+). The styles I am using are below, along with an explanation of my problem.
AppTheme extends Theme.AppCompat.Light.NoActionBar
<item name="android:statusBarColor">#color/transparent</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#color/welbe_red_transparent</item>
FullscreenTheme extends AppTheme
<item name="android:windowNoTitle">true</item>
<item name="android:statusBarColor">#color/transparent</item>
<item name="android:windowTranslucentNavigation">true</item>
This makes the app look like this
If I remove the android:windowTranslucentNavigation style, or set it to false in Fullscreen, it fixes the navigation bar issue. The problem is the status bar turns completely white instead of staying transparent and displaying the content behind it.
I have tried using fitsSystemWindow="true" in my layouts, but it didn't fix the issue. Anyone know why this is happening?
android:windowTranslucentNavigation does one thing that android:statusBarColor doesn't do, which is requesting the SYSTEM_UI_FLAG_LAYOUT_STABLE and SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN flags.
These are the ones that you need to request in order to draw behind the status bar.
Request them in the onCreate of your Activity:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
Alternatively you can also simply set your apps theme background and that will also pop up behind your status bar.
More information here.
As far as I know there's no proper way to set the color of the status bar on APIs lower than 19.
For API 19+ you can use a similar attribute to windowTranslucentNavigation only for the status bar:
<item name="android:windowTranslucentStatus">true</item>
Notes:
The reason you were getting a white status bar is because of
<item name="android:statusBarColor">#color/transparent</item>
There are some hacks that work on specific manufacturer devices, but I wouldn't use them myself.
I struggle with this for over 3 hours. Wrap everything in a CoordinatorLayout it is the only one that seems to pay attention to the fitsSystemWindow="true" or "false"
This is my main activity fragment
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/layout_google_map"/>
<include layout="#layout/layout_toolbar_transparent"/>
<include layout="#layout/layout_action_buttons"/>
<include layout="#layout/layout_bottom_sheet"/>
</android.support.design.widget.CoordinatorLayout>
this is my toolbar layout
<android.support.design.widget.CoordinatorLayout
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.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:theme="#style/ToolbarTheme"
app:popupTheme="#style/AppTheme.PopupOverlay">
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="?actionBarSize"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:adjustViewBounds="true"
app:srcCompat="#drawable/ic_fynd_logo_red"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CoordinatorLayout>
as you can see, my fragment layout makes the google map be drawn under the status bar.
I have an action bar where the company's logo goes.
And other ui buttons "layout_action_buttons" also wrapped in a Coordinator layout , so the fitsSystemsWindows works.
Check it out.
To achieve this in any activity
Add the style:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowBackground">#android:color/white</item>
</style>
Use CoordinatorLayout as root layout in XML
In oncreate() method, before setcontentview use
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
For the latest android version R and backward compatibility, this works for me.
WindowCompat.getInsetsController(window, window.decorView)?.isAppearanceLightStatusBars =false /* true for dark icon on StatusBar and false for white icon on StatusBar */
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowCompat.getInsetsController(window, window.decorView)?.show(WindowInsetsCompat.Type.statusBars())
ViewCompat.setOnApplyWindowInsetsListener(findViewById(android.R.id.content)) { rootView, insets ->
val navigationBarHeight = insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom
rootView.setPadding(0, 0, 0, navigationBarHeight)
insets
}
For Fragment, you can use activity?.window...

Categories

Resources