There is such code:

@Override protected void onCreate(@Nullable Bundle savedInstanceState) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Window w = getWindow(); w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } super.onCreate(savedInstanceState); setContentView(R.layout.sort_by_activity); 

http://i7.5cm.ru/i/dT9l.png

The toolbar is too close to the status bar (when you hide an item, they generally overlap each other).

Changing the Gradle version and updating the libraries to the latest results did not bring. With the markup also tried to change the values, no changes.

Did anyone meet with a similar one and I will be glad to hear, at least, the direction in which to dig, for I can’t imagine what it can be connected with.

Nevertheless, I will indicate the Gradle - 2.14.1 version Gradle - 2.14.1 and the Plugin version - 2.1.3

Versions of libraries:

 android { compileSdkVersion 24 buildToolsVersion "24.0.1" defaultConfig { applicationId "com.asgard.power" minSdkVersion 15 targetSdkVersion 24 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } android { defaultConfig { vectorDrawables.useSupportLibrary = true } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.2.1' compile 'com.android.support:design:24.2.1' compile 'com.android.support:recyclerview-v7:24.2.1' compile 'com.android.support:cardview-v7:24.2.1' compile 'com.roughike:bottom-bar:1.3.4' 

UPD:

wrapped in AppBarLayout:

 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/sortByCoordinator" android:parentActivityName=".ActivityMain" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/coordinatorBackground" android:clickable="true"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> <android.support.v7.widget.Toolbar android:id="@+id/sort_toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@drawable/orange_gradient" android:clickable="true" android:fitsSystemWindows="true" app:layout_scrollFlags="scroll|enterAlwaysCollapsed" app:popupTheme="@style/Theme.AppCompat.Light.NoActionBar" app:theme="@style/Theme.AppCompat.NoActionBar" /> </android.support.design.widget.AppBarLayout> </android.support.design.widget.CoordinatorLayout> 

UPD: So it looks like with CollapsingToolbar on the advice @YuriSPB:

 <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar_layout" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginStart="48dp" app:expandedTitleMarginEnd="64dp" android:fitsSystemWindows="true"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:layout_marginTop="6dp" android:paddingTop="6dp" android:background="@drawable/blue_gradient" android:clickable="true" android:fitsSystemWindows="true" app:layout_collapseMode="pin" app:layout_scrollFlags="scroll|enterAlwaysCollapsed" app:popupTheme="@style/Theme.AppCompat.Light.NoActionBar" app:theme="@style/Theme.AppCompat.NoActionBar" /> </android.support.design.widget.CollapsingToolbarLayout> 

Throws errorInflate .

UPD:

Styles:

 <resources> <style name="AppDefault" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@android:color/transparent</item> <item name="colorPrimaryDark">@android:color/transparent</item> <item name="colorAccent">@color/colorAccent</item> <item name="android:statusBarColor">@android:color/transparent</item> <item name="android:windowTranslucentStatus">false</item> <item name="android:windowDrawsSystemBarBackgrounds">false</item> </style> <style name="MyCustomTabLayout" parent="Widget.Design.TabLayout"> <item name="tabTextAppearance">@style/MyCustomTabTextAppearance</item> <item name="tabIndicatorHeight">6dp</item> </style> <style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab"> <item name="android:textSize">14sp</item> <item name="textAllCaps">true</item> </style> </resources> 
  • Wrap the toolbar in AppBarLayout - Yuriy SPb
  • @YuriySPb updated - Silento
  • And? .. Still not working? Then try to remove from the Toolbar and AppBarLayout android:fitsSystemWindows="true" - Yuriy SPb
  • @ YuriySPb did not help - Silento
  • one
    I do not think. If the tips above did not help, then the problem is either inattention or hidden deeply. Try building a simple project with this markup only. So that you can clone and reproduce the problem. - YurySPb

4 answers 4

It was possible to solve thanks to a friend. Through styles:

  <style name="AppDefault" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@android:color/transparent</item> <item name="colorPrimaryDark">@android:color/transparent</item> <item name="colorAccent">@color/colorAccent</item> <item name="android:windowTranslucentStatus">false</item> <item name="android:windowTranslucentNavigation">false</item> <item name="android:navigationBarColor">@color/head_bottom_sheet_background</item> <item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:statusBarColor">@android:color/transparent</item> <item name="android:windowBackground">@drawable/blue_gradient</item> <!-- Other --> <item name="android:windowActionBarOverlay">true</item> <item name="android:windowNoTitle">true</item> <item name="android:windowContentOverlay">@null</item> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> </style> 

I give the award to @AlexVorobiev as the first to guess that it will not work through flags.

  • Thank you, glad that you were able to solve the problem - Alex Vorobiev

In addition to the tag for the transparent style of the statusbar, you can also use the following: <item name="android:statusBarColor">@android:color/transparent</item>

In conjunction with

<item name="android:windowDrawsSystemBarBackgrounds">true</item>

Everything works fine and nothing hits the status bar :) At least for me. And as advised by @YuriSPb leave android:fitsSystemWindows="true"

  • From uni come, try. If you succeed, you will find out first :) - Silento
  • Unfortunately, these parameters in the styles are already specified and even with them it still does not work. - Silento

Try removing the next line w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); . It worked for me.

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:id="@+id/sortByCoordinator" android:parentActivityName=".ActivityMain" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:clickable="true"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true"> <android.support.v7.widget.Toolbar android:id="@+id/sort_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/gradient" android:clickable="true" android:fitsSystemWindows="true" app:layout_scrollFlags="scroll|enterAlwaysCollapsed" app:popupTheme="@style/Theme.AppCompat.Light.NoActionBar" app:theme="@style/Theme.AppCompat.NoActionBar" /> </android.support.design.widget.AppBarLayout> 

Activity

 public class MainActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { Window w = getWindow(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } 

}

Styles

 <resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@android:color/transparent</item> <item name="colorPrimaryDark">@android:color/transparent</item> <item name="colorAccent">@color/colorAccent</item> </style> 

  • Unfortunately, in this case, the status bar turns black, although everything is normalized. But the point is to transfer the gradient to the status bar. - Silento
  • I got that gradient effect, but in this solution I had to change the colorPrimary and colorPrimaryDark in @android:color/transparent . - Alex Vorobiev September
  • so, my statusbar turned white. Faced with this? - Silento
  • Next, I changed the attribute value: android:layout_height="match_parent" in -> android.support.v7.widget.Toolbar and deleted w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); . - Alex Vorobiev September
  • No, with android: background = "@ drawable / orange_gradient" worked. I'll try to see if I missed something. - Alex Vorobiev September

Tried android:layout_marginTop="3dp" ?

  • I tried, it did not help, making the padding - partly better, but when you hide the toolbar - the tabs do it. - Silento