android:fitsSystemWindows not working

前端 未结 6 829
走了就别回头了
走了就别回头了 2020-12-10 11:03

In my theme I defined the following rules to draw my views behind the status bar:

@android:color/transparent

        
相关标签:
6条回答
  • 2020-12-10 11:09

    for me the problem was that the keypad hides an editText field which is placed at the end of the activity ..I have tried every solution out there and nothing works. I was using this code before the call to setContentView() method to make the status bar transparent:

       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                Window w = getWindow(); // in Activity's onCreate() for instance
                w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            }
    

    I removed it and also removed android:windowSoftInputMode="adjustResize|adjustPan" from the maneifest file and now it works.

    0 讨论(0)
  • 2020-12-10 11:20

    There is an easy way to do this. Make sure you set the 2 elements in styles of the theme applied to your activity.

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        ....
        <item name="colorPrimaryDark">@android:color/transparent</item>
        <item name="android:fitsSystemWindows">true</item>
        ...
    </style>
    

    No need to do add android:fitsSystemWindows in your layout. This will directly add to it.

    0 讨论(0)
  • 2020-12-10 11:25

    Make this changes

    1. Manifest - create a theme and add window background of your like
    2. toolbar in xml -  add the same background in toolbar
    

    this works for me.

    0 讨论(0)
  • 2020-12-10 11:26

    I meet the same problem in Android 4.4

    My problem is <item name="android:windowTranslucentStatus">true</item>

    conflict with <item name="android:fitsSystemWindows">true</item>

    My way is remove <item name="android:windowTranslucentStatus">true</item>

    0 讨论(0)
  • 2020-12-10 11:27

    Use CoordinatorLayout as root for your view, it worked for me.

    <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">
    
    0 讨论(0)
  • 2020-12-10 11:32

    My problem was most likely related to multiple/nested fitsSystemWindows attributes which does not work as I found out later. I solved my problem by applying the attribute to one view, and then copy the paddings to other views that need them via an ViewTreeObserver.OnGlobalLayoutListener. That is an ugly hack, but does its job for now.

    0 讨论(0)
提交回复
热议问题