I want to draw my layout behind transparent status bar.
I'm using conductor's controllers for implementing my app's screens, all of them have white status bar but one need it to be fully transparent. I can't use windowTranslucentStatus flag when entering this controller because it causes my layouts to jump a little bit when controller enters and exists the screen. I think that custom window insets could help to have one controller to be drawn behind status bar without layout's jumping but I can't figure out how to it. Could anyone help me with this please?
Use android:fitsSystemWindows="true" in the root view of your layout.
What does fitsSystemWindows do?
System windows are the parts of the screen where the system is drawing either non-interactive (in the case of the status bar) or interactive (in the case of the navigation bar) content.
Most of the time, your app won’t need to draw under the status bar or the navigation bar, but if you do: you need to make sure interactive elements (like buttons) aren’t hidden underneath them. That’s what the default behavior of the android:fitsSystemWindows=“true” attribute gives you: it sets the padding of the View to ensure the contents don’t overlay the system windows.
Source
To do that I would recommend you to hide the status bar and enable full screen window. Try below, it works.
Step 1: Create theme in style.xml
<style name="FullScreen" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
Step 2: Apply the theme for activity in manifest file, can also apply theme at the application level too. For example have added in activity level.
<activity
android:name=".MainActivity"
android:theme="#style/FullScreen" />
Related
I'm new to Android studio and I figured out how I can send my application to my phone. The problem is, In the preview, At the bottom, it has this auction bar (See photo) Is there a way to get rid of that? Because my phone (Samsung Galaxy S6 Edge) Does not have that, And it sits in the way if I want to place something at the very bottom. Because in android studio it may be at the very bottom, But on my phone, it isn't.
Also, Is there a way to make that top bar, That is now black, Sort of transparent? So it takes the colour of the background? You see it in a lot of apps. As I mentioned, I'm very new in android studio so sorry.
Thanks in advance
The control bar at the bottom is part of the emulator aka any phone without hard buttons. You can toggle to full screen and it will hide it for you.
For example code simply create new activity and select fullscreen activity. You will see that it manages it by touch of surface to reappear and timer to dissappear. Just remove that bloat and handle it yourself. Done !
As for the status bar at the top, it uses your activity default background. So if you want to change this go to your styles and add a background to your AppTheme and this will be the default background color of unspecified areas instead of black.
Example:
<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="android:windowBackground">#color/blue</item>
<item name="android:actionMenuTextColor">#color/white</item>
</style>
The windowBackground color will drive the background color of unspecified areas unless you override the theme on any particular activity in the manifest. Goodluck.
I'm trying to make just one activity of my app overflowing behind the software keys, like this
What I already did was to put in my theme definition the following statements
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
and then enabled it on the listView I wanted to overlap
android:fitsSystemWindows="true"
android:clipToPadding="false"
What happened was that my app did overlap on status bar and button bar, but this on EVERY activity and not just on the one I put the two rows above.
Also, it messed up my activity margins: the first row of my application drawer is hidden, and the top of my main fragment as well.
I thought fitsSystemWindows was meant to solve this kind of issues, so I added it to my theme
<item name="android:fitsSystemWindows">true</item>
but nothing changed.
So the question is apparently simple: how can I get the translucent bottom bar, with one of my activities flowing behind it, without messing up the top part of my app and without (if possible) having the same effect on all other activities?
Thank you in advance to each of you fellow helpers.
As Eluvatar stated if I need to have this effect on just one activity the best thing to do is to define a custom theme and assign it just to this activity. That's what I did, I defined an empty style in styles.xml and overrided it in values-v19/styles.xml putting just
<!--<item name="android:windowTranslucentStatus">true</item>-->
<item name="android:windowTranslucentNavigation">true</item>
Then I assigned - in AndroidManifest.xml, the proper style to the activity by using
android:theme="#style/Theme.Style.I.Created.For.This.Activity"
Disabling the first row allowed the activity to just overlap the navigation bar without popping out on the status bar. Margins seem ok as well.
I hope this is going to help somebody else someday.
I have read similar questions for this problem but i couldn't find my answer anywhere. In order to solve the overdraw problem i use the following:
<style name="MyTheme" parent="#android:style/Theme.Holo">
<item name="android:windowBackground">#null</item>
</style>
When i use this in my activity which has an ActionBar, the background color of the action bar also changes to null. How can i fix this? If i set the color of the action bar separate the blue divider is being disappeared. How can i set to null the background of the frame below to action bar divider?
I'd suggest the following:
Create 2 separate themes: one for the activity with the action bar, the other one for the one without it.
For the activity without the action bar, use the theme you provided in your post, i.e.:
<style name="MyTheme" parent="#android:style/Theme.Holo">
<item name="android:windowBackground">#null</item>
</style>
For the activity with the action bar, simply create a theme which doesn't have the android:windowBackground item but instead sets a specific background colour that you want to have in that activity. Then, in the layout file that you inflate for the activity, delete the android:background attribute (because it'll already be set by the theme).
To make it a bit more visual, the theme would look like this maybe:
<style name="MyThemeForActivityWithoutActionBar" parent="#android:style/Theme.Holo">
<item name="android:background">#android:color/black</item>
</style>
And the activity's layout would maybe look like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black" // remove this
android:orientation="vertical" >
...
</LinearLayout>
I indicated which line I'd remove in the snippet above.
Does this help? :)
Solve your overdraw problem in a different way. Set the background you need in android:windowBackground and instead remove backgrounds from your layouts. Then you'll get action bar background back.
Using null window background is a bad solution anyway, exactly because it causes unintended side-effects, like rendering artifacts (or in your case missing action bar background). Chet Haase explains it in detail in Developing for Android VIII
The Rules: User Interface:
Avoid Null Window Backgrounds
One technique to avoid overdraw is to eliminate the window background
in situations where the views in the hierarchy all have opaque
backgrounds. That is, the user will not see the background of the
window if the view hierarchy completely covers that background with
one or more opaque views.
Eliminating the window background can be a valid technique, but it
tends to be a complicated way to solve overdraw issues, and can often
result in rendering artifacts in different situations. While it is
possible to set a null window background in the application manifest,
this can result in graphics artifacts due to the system not being able
to draw the starting window correctly. A more correct way to do this
is to leave the starting window background in place in the manifest,
but set it to null in the activity’s onCreate() method, by calling
getWindow().setBackground(null). But even this approach can cause
artifacts. For example, if the keyboard/IME is set to adjustResize and
is then animated in for an activity that has a null background, there
may be artifacts behind the keyboard as it animates in because the
window manager has nothing to draw for that background. Also,
fullscreen ListViews may have artifacts with overscroll bounce gaps
(which can be worked around with
ListView.setOverscrollFooter/Header()).
The correct way to address overdraw issues for this situation is to
actually use the starting window. Instead of having containers with
their own opaque background color between the window background and
views, put the background drawable you want on the window itself with
the windowBackground theme attribute and let those intervening
containers keep their default transparent backgrounds.
I've created a separate xml style file targeting KitKat and I've managed to change the color of the status bar. The only side-effect as seen on the picture, all the content is now moved up beneath the status bar. My question is how can I change the color of the status bar without overlaying this or how can I know the exact top margin I need to put on my content so its starts after the ActionBar and not beneath. Of course I need this to behave as expected on all screen sizes and densities. Thank you
values-v19/styles.xml
<style name="ThemeSelector" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
You should add the following to the top of the view(s)
android:paddingTop="?android:attr/actionBarSize"
If you're using the Support Library for the action bar, you need to remove the android: prefix
android:paddingTop="?attr/actionBarSize"
By enabling translucent system bars, your layout will fill the area behind the system bars, so you must also enable fitsSystemWindows for the portion of your layout that should not be covered by the system bars.
EDITED
You can add
android:fitsSystemWindows="true"
in your XML File
Remove from your layout
android:fitsSystemWindows="true"
I want to hide the Status Bar in my app and maintain the ability for the virtual keyboard to adjustResize for ScrollViews.
This:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
does not work because it breaks all ScrollViews preventing the adjustResize from resizing the view allowing the user to scroll when the keyboard is visible, so this is not an acceptable answer.
I've got:
<item name="android:windowNoTitle">true</item>
In my base theme, and I tried putting that setting directly into the Manifest entry for my activity, but it doesn't do anything.
I am using ActionBarSherlock in my app so I can provide a uniform UI to my users and it requires that I use one of three base themes:
In order for the custom action bar implementation to function your
application must use Theme.Sherlock, Theme.Sherlock.Light, or
Theme.Sherlock.Light.DarkActionBar, or your custom theme must use one
of the aforementioned as its parent.
So, I've configured my Theme this way:
<style name="LightNoTitleBar" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
</style>
and I've got android:theme="#style/LightNoTitleBar" in my manifest entry for this activity.
So, how can I hide the status bar given the above restrictions?