I want to have the content of my layout being displayed under the navigation bar (also called translucent navigation bar). After reading on the internet, it says all you have to do is add this 2 items to style applied to the activity:
<item name="android:navigationBarColor">#android:color/transparent</item>
<item name="android:windowTranslucentNavigation">true</item>
The result is, that the navigation bar is light gray and not transparent. How do all the people solve this ?
Problem was the attribute
android:fitsSystemWindows="true"
in the root view of my layout (in this time CoordinatorLayout). This attribute prevents the content of the layout to draw behind the status and navigation bar.
Related
Guys I want to have translucent status bar with black background navigation buttons. Just like Netflix App as shown in picture. I tried really hard to find any way but I failed to achieve this. Any Idea?
Add in styles.xml in Base Application style
Change status bar color : <item name="android:statusBarColor">#color/blackColor</item>
For Translucent status bar : <item name="android:windowTranslucentStatus">true</item>
For navigation bar color : <item name="android:navigationBarColor">#color/blackColor</item>
in layout file use : android:fitsSystemWindows="true" in root layout.
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" />
I'm try to developing an app with a navigation drawer from a template found on github.
In style.xml i have:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#ff0000</item>
<item name="colorPrimaryDark">#0000ff</item>
and the status bar in navigation drawer is ok.
When i click the button it runs this command:
getWindow().setStatusBarColor(Color.GREEN);
Now the status bar color in navigation drawer is no more translucent
How restore status bar color to translucent?
The difference is that the xml defined colors colorPrimary and colorPrimaryDark are not really used to directly set the status bar color.
Actually the statusbar is completely transparent all the time and only the underlaying View is colored. Thats why it can have another color on the left than on the right side (have a look at your second screenshot). If you now call getWindow().setStatusBarColor(..) you indeed color the statusbar directly and over-draw the color of both Views. So it needs to stay transparent!
What you really want to do, is changing the color of the View underlaying the status bar, which is done with the ScrimInsetsFrameLayout class.
Have a look at this question and this class from the library you provided
There you should find all the necessary information to change only the color of the area you want to.
In case you really just want to reset the color:
getWindow().setStatusBarColor(Color.TRANSPARENT);
For an app I'm building, I used the Design Support Library.
I created an app that uses a TabLayout. A little feature of the app is that when the user changes tabs, the color of both the TabLayout and the Toolbar change to a corresponding color. We're also using the new NavigationView, to present the user with a Material design DrawerLayout.
However, changing the color of both the TabLayout and the Toolbar is no problem at all, we do it in the lines of the following;
String hexColor = String.format("#%06X", (0xFFFFFF & getResources().getColor(R.color.primaryColor)));
getBaseActivity().getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(hexColor)));
mTabLayout.setBackgroundColor(getResources().getColor(primaryColor));
This is all good, and working like it's supposed to. The problem appears when I try to set the Status bar background. Since the material design specification tells us that the NavigationDrawer should get some special treatment, below image shows how the status bar is actually a form of translucent. The Navigation Drawer falls over my main fragment while the navigation bar is above both, being a translucent bar.
My first thoughts were that it's just a bar with a #7000 hexadecimal value or something, but I couldn't be further from the truth. Doing that doesn't change the color of the actual color it should "darken".
After that I just tried setting the darker version of the required color as the background for the status bar like so;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getBaseActivity().getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(R.color.primaryColor));
}
But after doing this, the complete functionality breaks. My view will look like this:
In essence, what can I do to fix this behaviour? I'd really like to change it so that the translucency feature still does what it needs to do according to the Material design spec, but also change the status bar's background color.
I think that there is always a translucent shadow behind it and you can not remove it. So you can try to play around with your colors alpha channel to achieve an acceptable result or think about a workaround solution like this:
As far as I see you just want that the status bar color is slightly different when the navigation drawer is open, right? So why not adding just a empty View with the desired color and the same height as statusbar in your NavigationDrawer layout to achieve the same effect?
Btw, there is a R.dimen.status_bar_height height specification.
Activity layout
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include layout="#layout/drawerlayout_main" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="#menu/drawer_menu" />
</android.support.v4.widget.DrawerLayout>
Activty theme, set statusBarColor to transparent
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
</resources>
NavigationView extends ScrimInsetsFrameLayout, it will draw some color at the statusbar position
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"