How to make transparent status bar - android

I'm trying to set a transparent status bar (like on a preview), but it looks like on video: https://yadi.sk/i/HcYJa3VB3WYGvL
Preview:
I tried set in styles xml's
<item name="android:windowBackground">#android:color/transparent< /item>
in different Layouts, also set
fitsSystemWindows = "true"
MainActivity.xml:
<android.support.v4.widget.DrawerLayout
...
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinator_container"
android:fitsSystemWindows="true"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
android:background="#color/color_primary">
<android.support.design.widget.CollapsingToolbarLayout
...
app:contentScrim="#color/color_primary"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/user_photo"
android:layout_width="match_parent"
android:layout_height="#dimen/profile_image_size"
android:scaleType="centerCrop"
android:src="#drawable/user_photo"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true"/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/AppTheme.PopupOverlay"
app:titleTextColor="#color/white"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_height="match_parent"
android:layout_width="wrap_content"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
...
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
.../>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
...>
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
v21/style.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/color_primary</item>
<item name="colorPrimaryDark">#color/color_primary_dark</item>
<item name="colorAccent">#color/color_accent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#color/color_accent</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>

There are two different cases:
1.If you want slightly transparent status bar(as you described in your question)
<style name="ThemeActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:background"> #null </item>
<!-- Support library compatibility -->
<item name="background">#null</item>
<item name="android:displayOptions"> showHome | useLogo</item>
<item name="displayOptions">showHome|useLogo</item>
2.For Completely transparent status bar:
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
check this answer you understand how things works.

add this in your theme
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
Set android:fitsSystemWindows=”true” to root container
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
add in your Activity

All you need to do is set these properties in your theme:
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
Your activity/container layout you wish to have a transparent status bar needs this property set:
android:fitsSystemWindows="true"
Already have answer od this question. Follow: Android Completely transparent Status Bar?

Related

CoordinatorLayout + AppBarLayout + Transparent Status Bar

My Scenario
I have an Activity(min SDK 19) with Coordinator and AppBar with Image and Scroll Behaviors, everything works fine except my status bar is not transparent nor translucent. Below is my
<style name="AppTheme.Collapsing">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
And I set that style to that Activity in manifest. Below is my xml layout.
These are images what I really want and what I got.
Image 1. I got like that, no transparent status bar.
Image 2. I want like that, with transparent status bar.
Image 3. Result after scroll, this is ok.
`<androidx.coordinatorlayout.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">
<com.google.android.material.appbar.AppBarLayout
android:fitsSystemWindows="true"
android:id="#+id/app_bar"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:fitsSystemWindows="true"
android:id="#+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.appcompat.widget.AppCompatImageView
app:srcCompat="#drawable/splash"
android:id="#+id/expandedImage"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7"/>
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/include_match_detail"/>
</androidx.core.widget.NestedScrollView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="#drawable/ic_logo"/>
`
You can try this style file
styles.xml;
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"/>
<style name="AppTheme.NoActionBar">
<item name="android:textColorSecondary">#color/white</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">#color/colorPrimaryDark</item>
<item name="android:windowDisablePreview">true</item>
<item name="colorPrimary">#android:color/transparent</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="colorPrimaryDark">#android:color/transparent</item>
</style>
also you need to create style for API Level 21
styles.xml for v21;
<style name="AppTheme.NoActionBar">
<item name="android:windowBackground">#color/colorPrimary</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="colorPrimary">#android:color/transparent</item>
<item name="colorPrimaryDark">#android:color/transparent</item>
<item name="android:colorAccent">#color/colorAccent</item>
<item name="android:textColorSecondary">#color/white</item>
</style>
then in your AndroidManifest.xml file you need to specify your style for your application
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:networkSecurityConfig="#xml/network_security_config"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
...
</application>
Another issue that i encounter when i try to make layout with transparent status.
I needed to put xml layout content inside DrawerLayout to make status bar transparent.
Change all android:fitsSystemWindows attribute from "true" to "false", this may help you get a translucent status bar,
but after you do this, your collapsingbarlayout is collapsed and the title in your toolbar may be shown in the status bar,
then you can try add android:layout_marginTop attribute in your toolbar and set its value to "20dp".

Toolbar is transparent pre-lollipop

So I've looked around and can't find an answer to this. I have a toolbar which shows up fine for anything lollipop and up but looks like the following for pre-lollipop devices:
Here is my code for the styles and everything:
style xml file
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:dropDownListViewStyle">#style/appStyleSpinner</item>
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/accentColor</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:windowNoTitle">true</item>
<item name="actionModeStyle">#style/myActionMode</item>
</style>
<style name="myActionMode" parent="#style/Widget.AppCompat.ActionMode">
<item name="background">#color/primaryColor</item>
</style>
toolbar xml file
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.Light">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
...
I figured out the problem! In my xml file for the main screen, I had
<include layout="#layout/app_bar"
android:id="#+id/app_bar"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/parmesan_bg"
android:scaleType="centerCrop"
android:contentDescription="photo of delicious dinner"/>
which was causing the toolbar to load behind the image instead of in front of it. So move the "include layout" to after the imageview and voila, problem solved!

Status bar turns white and does not show content behind it

I am trying out AppCompat on Marshmallow. And I want to have a transparent status bar however it turns white. I've tried a couple solutions but they didn't work for me (Transparent status bar not working with windowTranslucentNavigation="false", Lollipop : draw behind statusBar with its color set to transparent). Here's related code.
My styles.xml
<style name="Bacon" parent="Theme.Bacon"/>
<style name="Theme.Bacon" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/theme_primary</item>
<item name="colorPrimaryDark">#color/theme_primary_dark</item>
<item name="colorAccent">#color/theme_accent</item>
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">true</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">#color/background_material_light</item>
</style>
<style name="Theme.Bacon.Detail" parent="Bacon"/>
v21
<style name="Bacon" parent="Theme.Bacon">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<style name="Theme.Bacon.Detail" parent="Bacon">
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
Activity
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" />
</FrameLayout>
Fragment
<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.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="192dp"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="32dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:statusBarScrim="#color/black_trans80">
<ImageView
android:id="#+id/photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#string/photo"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/anim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
I found the answer in this link:Status Bar Color not changing with Relative Layout as root element
So it turns out we need remove the
<item name="android:statusBarColor">#android:color/transparent</item>
in styles.xml(v21). And it works just fine for me.
(A little late to the party but it might help someone)
I had the exact same problem. Somehow, some activities were normal while new ones I created were showing white status bar instead of colorPrimaryDark value.
After trying several tips, I noticed that the normal-working activities where all using CoordinatorLayout as the root of the layout, while for the others I had replaced it by regular layouts because I didn't need the features (animation, etc) provided by CoordinatorLayout.
So the solution is to make CoordinatorLayout the root layout, and then inside of it add your former layout root. Here is an example:
<?xml version="1.0" encoding="utf-8"?>
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
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="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<!-- your activity content here-->
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
PLEASE NOTE that without android:fitsSystemWindows="true" this solution doesn't work for me.
Tested on Lollipop and Marshmallow
You have to add this property on your style to see the content
<item name="android:windowLightStatusBar" tools:ignore="NewApi">true</item>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
</style
Just Replace this , statusBarColor should be your expected color and not TRANSPARENT
Add this in your style.xml
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
and this in your onCreate();
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
Just put this item in your v21\styles.xml :
true
It should look like this :
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
After unsuccessfully trying all of the above I found that explicitly setting the theme fixed the issue.
setTheme(R.style.AppTheme);
That has to go before the super.OnCreate() in your activity.
I faced the same issue. What i did was, in the "v21/styles.xml" file a changed the value true:
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
to:
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:statusBarColor">#android:color/transparent</item>
You'll see that line of code in values/styles/styles.xml(v21) . Remove it and that solves the issue
Link to this answer
I fixed my issue by changing my Activity layout from FrameLayout to RelativeLayout. Thanks everybody who tried to help!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/theme_primary_dark"
android:fitsSystemWindows="true" />
</RelativeLayout>
Try hierarchy-viewer or ViewInspector. These tools might help you.
Just remove following tag from style v21
#android:color/transparent
This works for me.
I have found solution for this -
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowLightStatusBar">true</item>
</style>
add this into your style and it will work for api 21 or above.
Better approach
Check your style.xml file where your NoActionBar theme is there.
Make sure its has parent as Theme.AppCompat.NoActionBar and also customize it by adding your color scheme. Finally set your themes in manifest as required.
Below is sample of my styles.xml file (ActionBar + NoActionBar).
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<!-- No ActionBar application theme. -->
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
For styles v23
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowLightStatusBar">true</item>
<item name="android:statusBarColor">#android:color/white</item>
</style>
For styles v21
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">#android:color/white</item>
</style>
If your v21/styles.xml contain
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
</resources>
Then,
Remove or comment below line or change colour of status bar,
<item name="android:statusBarColor">#android:color/transparent</item>
Its working fine. Hope this is helpful. Thanks.
For me it worked by doing the following :
Set the theme .NoActionBar
Wrap the Toolbar in android.support.design.widget.AppBarLayout
Make android.support.design.widget.CoordinatorLayout as the parent layout.
Essentially it is the third step that draws the status bar in the colorPrimaryDark otherwise it is not drawn if you using NoActionBar theme.
2nd step will give your toolbar that overlay.
[
Expand res -> values -> styles directory from project panel.
Open styles.xml (v21)
USE ANY ONE FROM BELOW WAYS
Change true to false in android:windowDrawsSystemBarBackgrounds property.
Change #android:color/transparent to #color/colorPrimaryDark in android:statusBarColor property.
Remove the android:statusBarColor propert line.
I'm not sure if it's late but i hope it helps someone.
* Make a fake view with transparent background that fits the layout, and make a coordinatorlayout as your root layout element.
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:fitsSystemWindows="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="#drawable/something" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
.... YOUR LAYOUT
you want this right?
try this. in [value] - [style.xml]
<style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar">
<item name="android:windowLightStatusBar">true</item>
</style>
you know, don't match apptheme - parent
good luck
Inside onCreate add the following:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
getWindow().setStatusBarColor(Color.WHITE);
and below
setContentView(R.layout.activity_main);
My guess is that this is caused by your android:windowBackground. Is #color/background_material_light a reference to white?
Check this
Toolbar turns white - AppBar isn't drawn after being scrolled off screen
https://code.google.com/p/android/issues/detail?id=178037#c19
I'm using libraries 23.0.0. and the bug still occurs.
Workaround for this is adding View that takes nearly no space and can be invisible. See the structure below.
<android.support.v4.widget.NestedScrollView
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout>
<android.support.v7.widget.Toolbar
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
app:layout_scrollFlags="scroll|enterAlways" />
<View
android:layout_width="match_parent"
android:layout_height=".3dp"
android:visibility="visible"/>
</android.support.design.widget.AppBarLayout>
This Questions on Stackoverflow.com refer to this bug too:
CoordinatorLayout Toolbar invisible on enter until full height
AppBarLayout - Layout sometimes invisible once it enters view (even if it's not entered)
If you are using RelativeLayout / CoordinatorLayout this is the solution that worked for me:
You have to use
CoordinatorLayout
AppBarLayout
Rember to use CoordinatorLayout instead of RelativeLayout (the performance is better and perfectly works with AppBarLayout)
This is how your fragment should starts
<?xml version="1.0" encoding="utf-8"?>
<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:background="#android:color/background_light"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:id="#+id/main.appbar"
android:layout_width="match_parent"
android:layout_height="300dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
>
...
Good coding!
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
add the 'windowTranslucentStatus' item in styles
Add this in your style.xml
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
Note : Status bar coloring is not supported below API level 21.
Window window = this.getWindow();
window.setStatusBarColor(this.getResources().getColor(R.color.colorPrimaryDark));
Add this 2 line in java file below

Why is using a material AppCompat theme causing full screen?

I'm trying to switch over an app to use Theme.Material, I have a toolbar setup with fitsSystemWindows set to true yet my activity extends below the navigation bars!!
Here's my theme
<style name="FlowTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:windowFullscreen">false</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="cpvColor">#color/accent</item>
<item name="cpvStrokeWidth">3dp</item>
<item name="cpvCircleAnimDuration">1400</item>
<item name="cpvSweepAnimDuration">950</item>
</style>
Nothing is triggerend in my activity to flag fullscreen
What's going on? how do I fix this so that it's not fullscreen?
Edit: Here's my main activity XML
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bg_color"
android:orientation="vertical">
<include
android:id="#+id/toolbar_actionbar"
layout="#layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ActMain"
tools:ignore="MergeRootFrame"
android:layout_below="#+id/toolbar_actionbar" />
</LinearLayout>
<fragment
android:id="#+id/fragment_drawer"
android:name="com.metalab.flow.ui.fragments.FrNavigationDrawer"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fr_navigation_drawer" />
this is the reason
Theme.AppCompat.Light.NoActionBar // i show no actionbar..
put this in your activity xml layout, if its linearLayout let it be the first child, if its RelativeLayout let it be on top and all children should align to it..
<android.support.v7.widget.Toolbar 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="wrap_content"
android:minHeight="?attr/actionBarSize"
app:theme="#style/FlowTheme" />
style
<style name="FlowTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:windowFullscreen">false</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="cpvColor">#color/accent</item>
<item name="cpvStrokeWidth">3dp</item>
<item name="cpvCircleAnimDuration">1400</item>
<item name="cpvSweepAnimDuration">950</item>
</style>
As it turns out I was using this class, for a core WebView bug fix https://github.com/madebycm/AndroidBug5497Workaround
Removing it's use fixed my issue, however the WebView resize bug lives on...
You are using wrap_content in your toolbar, and if you havent given support to it, then it hasn't content to show. I recomend you that change the height of the toolbar to:
android:layout_height="?attr/actionBarSize"
And you should give support in your java file to show the title and buttons:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(toolbar);
EDIT: I read some of other replies, and I add more info because I suppose that you had the toolbar defined in other xml. This is an example of toolbar that you should include:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:translationZ="4dp"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />

transparent Actionbar with AppCompat-v7 21

Is there a way to make the ActionBar transparent in Material Design via Appcompat-v7 21? This is not working unfortunately.
<item name="colorPrimary">#android:color/transparent</item>
Also not the old:
<style name="Widget.Styled.ActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="android:background">#android:color/transparent</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ACTION BAR STYLES -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
<item name="windowActionBarOverlay">true</item>
</style>
Actually, it's quite easy and simple.
Just ensure that you use RelativeLayout to lay Toolbar and the body.
Put the Toolbar in the last.
Put transparent color for android:background attribute of the Toolbar
This is an example of a working code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="vertical">
<fragment
android:id="#+id/fragment_editor"
android:name="ichsan.myapp.HelloFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/fragment_editor" />
<android.support.v7.widget.Toolbar
android:id="#+id/my_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#10000000"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"/>
</RelativeLayout>
Hope it answers the question.
Step:
1. put below style into v21\styles.xml
<style name="TransperantToolbar" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item>
</style>
2. Your toolbar xml code
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="#style/TransperantToolbar"/>
None of the above did the trick for me (or at least not by themselves)
using appcompat v7 23 and a CoordinatorLayout, which is most likely the culprit. If you are going that route, then you probably have a main activity layout that looks like
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.farmdog.farmdog.MainActivity">
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_anchor="#+id/appbar"
app:layout_anchorGravity="top"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--android:theme="#style/AppTheme.AppBarOverlay">-->
...
Notice the two layout anchor lines above - those did it for me.

Categories

Resources