Extend Toolbar behind Status Bar - android

I have an application in which I would like to change the color of the Toolbar fairly often.
Right now, I am manually setting the Status Bar color and the Toolbar color (where the status bar color is a darker version of the toolbar color).
Is it possible to instead use
<item name="android:windowTranslucentStatus">true</item> in my style and have my Toolbar extend behind the status bar? That way, I wouldn't have to manually create a dark color and manually set the status bar color in addition to the toolbar color. This would also allow the navigation drawer to show in front of the status bar color and behind the actual status bar (Right now the top of the navigation drawer isn't shown because the status bar is a solid color)

i think what you are looking for is this
android:fitsSystemWindows
Boolean internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows. Will only take effect if this view is in a non-embedded activity.
Must be a boolean value, either "true" or "false".
This may also be a reference to a resource (in the form "#[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol fitsSystemWindows.

Try this to put toolbar behind status bar:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
before setContentView in Activity and add to styles windowTranslucentStatus, it makes Top of a Drawer visible

Related

How to implement system bars insets with edge-to-edge gesture navigation?

I'm trying to add the edge-to-edge stuff for the gesture navigation bar to the Tip Time app from Google. I added the transparent navigationBarColor XML tag to themes.xml as well as the following code to the onCreate() function of MainActivity.kt:
This was directly copy-pasted from the documentation. Android Studio says that "it cannot find a parameter with this name" for each of the three margins. I noticed that changing the parenthesis right after <ViewGroup.MarginLayoutParams> to curly braces fixes the compiler error. Maybe the documentation is just wrong?
Anyways, even after fixing that, the app still doesn't look right:
As you can see, the entire view gets shifted up slightly and the "Cost of Service" TextView is partially cut-off by the app bar. What would I need to change to implement the system/navigation bar insets for edge-to-edge content so the UI looks nice? Also, as a side-question, how can I change the dark blue color of the system status bar to match the color of the app bar so that they look blended?
As per documentation for edge to edge contents:
Draw behind the status bar if it makes sense for your content and
layout, such as in the case of full-width imagery. To do this, use
APIs such as AppBarLayout, which defines an app bar pinned to the top
of the screen.
So, while handing the window insets (especially the top one), you can't use the default ActionBar, instead you need to customize that with AppBarLayout and ToolBar, and to make it act as the ActionBar, use setSupportActionBar(), and a NoActionBar app theme; it'd be <style name="Theme.TipTime" parent="Theme.MaterialComponents.DayNight.NoActionBar"> in the shared repo.
the entire view gets shifted up slightly and the "Cost of Service" text field is partially cut-off by the app bar.
The reason that the sample uses the default ActionBar instead of a customized one; when it comes to handle the top window insets, it won't affect the default ActionBar; notice that you pass in the activity's root layout to setOnApplyWindowInsetsListener callback, and as the ActionBar is not a part of the activity, it won't be affected. Therefore the activity is shifted up behind the ActionBar when the top inset is removed. So, to solve this you have either to totally remove the default ActionBar or to use a custom toolbar instead.
Also, as a side-question, how can I change the dark blue color of the system status bar to match the color of the app bar so that they look blended?
Use a transparent status bar color in the app's theme:
<item name="android:statusBarColor" tools:targetApi="l">#android:color/transparent</item>

Android Studio make status bar background complete transparent and change icon color

i need to make the status bar transparent, and change the icon color to a darker grey. Because i am using a viewpager and the layout must go below the status bar, i also tried it with
"windowTranslucentStatus=true"
But with it i cant change the color of status bar and it wasn't transparent, it was a darker grey and light transparent. And i want to change the color of the status bar in the layout when it is transparent. So i can create on the top of my layout, a view that has a height of 25dp and can change there the color, and when i am swiping, the color on the status bar should swiping too.
If im not doing this it look very terrible.
Thank you
Try this for status bar
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
}
Works with ActionBarActivity.

CollapsingToolbarLayout: statusBarScrim for expanded state?

I'd like to use a CollapsingToolbarLayout to achieve an effect as in the following image:
To accomplish this, I first tried to set the status bar background color to a 30% opacity black in my theme. This works fine for the expanded state and achieves the intended effect.
However, I'd also like to use #color/primaryColorDark for the status bar as background when the CollapsingToolbarLayout is collapsed. So I set app:statusBarScrim to #color/primaryColorDark, but because the status bar background is set to semi-transparent black in the theme, the color is darker than #color/primaryColorDark.
How do I set a status bar scrim that is used when the CollapsingToolbarLayout is expanded? CollapsingToolbarLayout has app:statusBarScrim for the collapsed state, but there is no such attribute for the expanded state. If I could do this, I can set the status bar to fully transparent and avoid the problem of the overly dark status bar in collapsed state.
Alternatively, is there a way to only set the status bar background to transparent when the CollapsingToolbarLayout is collapsed?

Change color of onscreen button bar

I'm trying to change the color of the on screen button bar:
I've managed to change the status bar color via the Android Manifest like this:
android:theme="#style/Theme.WebViewApp.Gray"
However I can't seem to figure out how to change from this purple color.
This section of screen called NavigationBar:
You can change color of NavigationBar using: http://developer.android.com/reference/android/view/Window.html#setNavigationBarColor(int)
This Method won't work on API version < 21.
To change navigation bar icon colors you can use the following answers: Change navigation bar icon color on Android

Overlay action bar with a translucent status bar

I'm trying to achieve the effect shown here: http://www.youtube.com/watch?v=6QHkv-bSlds&t=15m48s by Nick and the boys. I can get the action bar to be overlayed, but cannot figure out how to extend this to the status bar. I would also like to know how they managed the transparent black background behind the navigation bar (but this isn't as crucial).
Any help / advice would be greatly appreciated as I currently have no idea how this is done (and am starting to worry it may just be an image rather than an actual implementation).
Edit: i know how to make the bars fully transparent (thats the easy part)! I dont know how to extend the actionbar background to appear behind the now transluscent status bar
I had the same question and found this library: https://github.com/jgilfelt/SystemBarTint
Have a look at line 300 in:
https://github.com/jgilfelt/SystemBarTint/blob/master/library/src/com/readystatesoftware/systembartint/SystemBarTintManager.java
setupStatusBarView() Adds a view to the window's decor. This allows you to later set a color/drawable to this view.
If using the SystemBarTint library, the following will allow you to force the status bar to a specified color, which you can then match to your action bar's background:
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintColor(Color.parseColor("#DD000000"));
In this case you would set your action bar's background to: #DD000000
As described in the Android 4.4 APIs:
You can now make the system bars partially translucent with new themes, Theme.Holo.NoActionBar.TranslucentDecor and Theme.Holo.Light.NoActionBar.TranslucentDecor. 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.
If you're creating a custom theme, set one of these themes as the parent theme or include the windowTranslucentNavigation and windowTranslucentStatus style properties in your theme.
In your case (where you want the ActionBar), the second option - including the two new properties into your theme - will give you a translucent Navigation and Status bar.
They are using the new Translucent system bars feature (on Android 4.4 and up).
Translucent system bars
You can now make the system bars partially translucent with new
themes, Theme.Holo.NoActionBar.TranslucentDecor and
Theme.Holo.Light.NoActionBar.TranslucentDecor. 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.
If you're creating a custom theme, set one of these themes as the
parent theme or include the windowTranslucentNavigation and
windowTranslucentStatus style properties in your theme.

Categories

Resources